Announcement Announcement Module
Collapse
No announcement yet.
DBRE with Oracle incorrectly names one-many relations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DBRE with Oracle incorrectly names one-many relations

    Given two tables that are related like this

    Person
    person_id
    name
    Address
    person_id
    street
    etc
    Running DBRE generates
    Code:
    privileged aspect Address_Roo_DbManaged {
        @ManyToOne
        @JoinColumn(name = "PERSON_ID", referencedColumnName = "PERSON_ID", nullable = false)
        private Person Address.personId;
    and
    Code:
    privileged aspect Person_Roo_DbManaged {
        @OneToMany(mappedBy = "personId", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
        private Set<Address> Person.addresses;
    Since the reference is to a Person object, and not to its Id field, the name of the reference should be person, not personId. Okay, Roo should get that right, but the fix is simple enough. Pull the personId field out of the generated code, put it in Address.java, and change the field name to person. Only problem is that Roo dosen't notice the relationship has changed and leaves the line in the Person_Roo_DbManaged.aj file. This tells Hibernate that there is a "personId" field in Address.java that it should use for mapping, when the field is really named person now. Okay, that can be fixed too, in the same way, but Roo really should be naming this refenerce correctly in the first place. And it should notice when the name changes and fix the generated matching relationship. It seems to defeat the purpose of having a RAD tool to manage your DB relationships if you have to then manually change every one.

    Is this fixed in 1.2.4? Is there an easy way around it that I'm not aware of?
    Last edited by cygnosis; Jun 21st, 2013, 03:35 PM.

  • #2
    It's not fixed in 1.2.4

    Originally posted by cygnosis View Post
    Given two tables that are related like this

    Person
    person_id
    name
    Address
    person_id
    street
    etc
    Running DBRE generates
    Code:
    privileged aspect Address_Roo_DbManaged {
        @ManyToOne
        @JoinColumn(name = "PERSON_ID", referencedColumnName = "PERSON_ID", nullable = false)
        private Person Address.personId;
    and
    Code:
    privileged aspect Person_Roo_DbManaged {
        @OneToMany(mappedBy = "personId", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
        private Set<Address> Person.addresses;
    Since the reference is to a Person object, and not to its Id field, the name of the reference should be person, not personId. Okay, Roo should get that right, but the fix is simple enough. Pull the personId field out of the generated code, put it in Address.java, and change the field name to person. Only problem is that Roo dosen't notice the relationship has changed and leaves the line in the Person_Roo_DbManaged.aj file. This tells Hibernate that there is a "personId" field in Address.java that it should use for mapping, when the field is really named person now. Okay, that can be fixed too, in the same way, but Roo really should be naming this refenerce correctly in the first place. And it should notice when the name changes and fix the generated matching relationship. It seems to defeat the purpose of having a RAD tool to manage your DB relationships if you have to then manually change every one.

    Is this fixed in 1.2.4? Is there an easy way around it that I'm not aware of?
    No Its not fixed in 1.2.4. My Person---Address looks just like yours. One question I have is why does it create a many-to-one/one-to-many instead of a one-to-one?

    Comment

    Working...
    X