Announcement Announcement Module
No announcement yet.
Is there any problem in making a Roo Entity Serializable? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there any problem in making a Roo Entity Serializable?


    I presume that it's a Eclipse Indigo bug, but since I'm using STS 2.9.2.RELEASE (Eclipse 3.7.2), I post my problem in this forum.

    In a Roo project I've manually created an interface:

    //package ...core;
    public interface Transaccion extends Serializable {}
    Then I've created an entity, that will be the base for a hierarchy, and I've changed it in order to implement the previous interface:

    entity jpa --class ~.core.padre.Padre --abstract --identifierColumn c_id --table t_padre --inheritanceType SINGLE_TABLE
    //package ...core.padre;
    @RooJpaActiveRecord(identifierColumn = "c_id", inheritanceType = "SINGLE_TABLE", table = "t_padre")
    public abstract class Padre implements Transaccion {
    The first child entity was created without a problem:

    entity jpa --class ~.core.hijo.Hijo --extends ~.core.padre.Padre --testAutomatically
    //package ...core.hijo;
    public class Hijo extends Padre {
    But it has a compilation error message ONLY in the java file (there is no other error messages, not in the Package explorer nor in the Problems view):

    The hierarchy of the type Hijo is inconsistent
    Can anyone help me with this issue?

    NOTE : if the interface doesn't extend Serializable, the error disappears.
    Last edited by jbbarquero; Jun 4th, 2012, 09:46 AM.

  • #2
    Wrong package for Base, this is a real compilation error.

    entity jpa --class ~.model.base.Base --abstract --identifierColumn c_id --table t_hierarchy --inheritanceType SINGLE_TABLE
    entity jpa --class ~.model.child.Child1 --extends ~.model.Base --testAutomatically


    • #3
      Actually I modified the script for privacy reasons, and it seems I introduced that error.

      The Roo entities aren't serializable, the embeddedIds are, so I wonder if there's something wrong with this approach, specially with JPA Active Records.*

      Besides, according some explanation that I found, the error (that only appears in the Java file) is due to the fact that the compiler can't reach the class in the jars that are in the build classpath.

      Maybe it's a lack of the AspectJ compiler in Eclipse: Serializable is in the classpath, but the actual class is the Java file plus the aspects woven into it.

      Nevertheless, I appreciate your response.


      • #4
        How do you mean exactly "Roo entities aren't serializable"?
        Last edited by MiB; Jun 3rd, 2012, 08:35 PM.


        • #5
          Is your objective here simply to make all classes implementing your interface serializable? Is the interface doing something beyond this?

          If not, does the problem occur if you implement Serializeable directly?


          • #6
            Also, I assume "Transaccion" is not a typo in the source? As you call the interface "Transaction" here.


            • #7
              Apologize for all the misunderstanding.

              I've repeated the script and I've update the first POST using the actual code generated by Roo.

              The problem still remains. STS shows a compilation error in an Entity that extends an Entity that implements an interface that extends Serializable (it's not a joke, I promise)



              • #8
                I verified this behavior with a much simpler test. Maven builds without complaints.


                • #9

                  In fact there is no global error in Eclipse. The error message only appears once you open the Java file.


                  • #10
                    I also now verified this doesn't happen —unsurprisingly — provided you implement directly
                    public abstract class Padre implements Transaccion, Serializable

                    Here the interface Transaccion also doesn't implement Serializable.
                    Last edited by MiB; Jun 5th, 2012, 07:47 AM. Reason: Clarification


                    • #11

                      An Entity that directly implements Transaction (that extends Serializable) doesn't have errors either.

                      But I still don't know why an indirection shows that error.


                      • #12
                        I meant it's unsurprising to me that an abstract class can implement Serializable.


                        • #13
                          It has not to be abstract, as long as it is a direct child, that's surprising for me.


                          • #14
                            There's a Serialization chapter 11 in Joshuas Blochs' Effective Java that probably can shed some light on this.

                            Search for Serialization and check out page 291 specifically for your situation.


                            • #15
                              Done, thanks MiB.

                              According Joshua Bloch...

                              Classes designed for inheritance should rarely implement Serializable, and interfaces should rarely extend it
                              That's my case. I'm not very convinced with this paragraph, but the remains of the chapter contains a lot of reason for NOT making the hierarchy Serializable.

                              However, it doesn't explain the problem with Eclipse, but I've found this: Eclipse bug: The hierarchy of the type AbstractSubClass is inconsistent

                              The last comment, Anttix 2011-11-12 08:31:46 EST, talks about Roo.