Results 1 to 6 of 6

Thread: Issues with ROO Generated hibernate mappings

  1. #1
    Join Date
    Oct 2010
    Posts
    5

    Default Issues with ROO Generated hibernate mappings

    Hi,

    I started using the DBRE tools in Roo 1.1.0 RC1. So far everything looked great. Every entity was created just fine and controller scaffolding worked a treat.

    However, when i run my application (inside STS 2.3.2 RELEASE) i get the following error.

    Code:
    Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.sdp.fess.domain.FeService.feServiceTypes in com.sdp.fess.domain.FeServiceTypes.ajc$interField$com_sdp_fess_domain_FeServiceTypes_Roo_DbManaged$feServices
    Here are the Roo generated mappings in feServiceTypes

    Code:
    privileged aspect FeServiceTypes_Roo_DbManaged {
        
        @OneToMany(mappedBy = "feServiceTypes")
        private Set<FeService> FeServiceTypes.feServices;
    And here is the mapping in the feService Class

    Code:
    privileged aspect FeService_Roo_DbManaged {
        
        @ManyToOne
        @JoinColumn(name = "Service_Type_Id", referencedColumnName = "Service_Type_Id")
        private FeServiceTypes FeService.feServiceTypes;
    Everything looks okay to me, but i'm not sure why this error is being thrown.

    Any ideas??

    Cheers

  2. #2
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Question

    I haven't tried DBRE yet, so take this as a total stab in the dark, but could Roo be getting confused by the fact that the name of the FeServiceTypes entity is already pluralised? Does this problem occur in a many-to-one relationship between two tables that aren't pluralised?
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  3. #3
    Join Date
    Oct 2010
    Posts
    5

    Default

    I managed to fix it by replacing the mappedBy attribute with a targetEntity attribute.

    Code:
    privileged aspect FeServiceTypes_Roo_DbManaged {
        
        //@OneToMany(mappedBy = "feServiceTypes")
        @OneToMany(targetEntity = feService.class)
        private Set<FeService> FeServiceTypes.feServices;
    From memory, this is how Roo 1.0.2 maps one to many relationships. This could be a possible bug in RC1...i'm not entirely sure - since using the mappedBy attribute is straight from Hibernate's reference guide.

  4. #4
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Question

    Quote Originally Posted by Tincho View Post
    I managed to fix it by replacing the mappedBy attribute with a targetEntity attribute.
    That doesn't sound right, for two reasons:

    1. The JPA provider shouldn't need the "targetEntity" attribute because the target entity type is already implied by the Set's generic type, i.e. FeService. Your app should still work without this attribute.
    2. The "one" end of a one-to-many relationship is usually the inverse end, because in the database, the other end has the foreign key. As the inverse end, your Set needs the "mappedBy" attribute in order to know which field of the FeService class the "feServices" Set corresponds to (because that class might have more than one FeServiceTypes field).

    Are you sure that your app didn't start working for some other reason?
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  5. #5
    Join Date
    May 2011
    Posts
    2

    Default same problem with persistence

    Hi,

    I get the same problem that was previously described but I'm struggling to fix it. I'm working with STS 2.6.1 and Spring Roo 1.1.3

    In my model I use this bidirectional relationship:

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "msgFichero")
    private Set<MsgIncidenciaFichero> msgIncidenciaFichero = new HashSet<MsgIncidenciaFichero>();

    and
    @ManyToOne(targetEntity = MsgFichero.class)
    @JoinColumn
    private MsgFichero msgFichero;

    The error I get is :

    The strange thing is that the application sometimes works but it crashes with the previous error as soon as I do any change to the MsgIncidenciaFichero - underlying DB table. The AJs are correctly generated, it just seems the hibernate mappings are not created for some reason.

    Any ideas?

  6. #6
    Join Date
    May 2011
    Posts
    2

    Default

    The error I've been talking about is: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on MsgIncidenciaFichero.msgFichero references an unknown entity: MsgFichero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •