Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo reverse eng. Hibernate JPA - issues with auto increment primary key column Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo reverse eng. Hibernate JPA - issues with auto increment primary key column

    I have two tables in Oracle
    CUSTOMER
    CUSTOMER_ADDRESS

    CUSTOMER table has a primary key named ID (auto generated column with a sequence). CUSTOMER_ADDRESS has a foreign key CUSTOMER_ID to refer CUSTOMER parent table.

    I have reverse engineered the database and I have the java classes and aspects.

    Relation formed in Customer_Roo_DbManaged.aj as follows:

    @OneToMany(mappedBy = "customerId", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
    private Set<CustomerAddress> Customer.customerAddresses;

    ID column looks like this:
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="my_seq_gen")
    @SequenceGenerator(name="my_seq_gen", sequenceName="CUSTOMER_SEQ")
    @Column(name = "ID")
    private BigDecimal Customer.id;
    //setter and getter methods

    This is giving me an error while committing the customer object with address.

    integrity constraint (XXX.Relation1) violated - parent key not found

    I tried changing the GenerationType to Sequential but still it did not work.
    Last edited by kumarkro; Jun 20th, 2013, 02:10 PM.

  • #2
    Is ti possible to attache your project here and tell what is your database?

    Comment


    • #3
      I am sorry, I cannot attach the entire project because i have lot of other things in it. I am using Oracle DB.

      persistence.xml file :

      <property name="hibernate.hbm2ddl.auto" value="update"/>

      DBRE XML looks like this:

      <table alias="XXXX" name="CUSTOMER">
      <column name="ID" primaryKey="true" required="true" scale="0" size="10" type="3,NUMBER"/>
      <column name="CUSTOMER_NAME" primaryKey="false" required="false" scale="0" size="50" type="12,VARCHAR2"/>
      <foreign-key foreignTable="CUSTOMER_ADDRESS" name="Relation1" onDelete="restrict" onUpdate="cascade">
      <option key="foreignSchemaName" value="XXXX"/>
      <option key="exported" value="true"/>
      <reference foreign="CUSTOMER_ID" local="ID"/>
      </foreign-key>
      <unique name="CUSTOMER_PK">
      <unique-column name="ID"/>
      </unique>
      </table>
      <table alias="XXXX" name="CUSTOMER_ADDRESS">
      <column name="ID" primaryKey="true" required="true" scale="0" size="10" type="3,NUMBER"/>
      <column name="ADDRESS1" primaryKey="false" required="false" scale="0" size="50" type="12,VARCHAR2"/>
      <column name="CUSTOMER_ID" primaryKey="false" required="true" scale="0" size="10" type="3,NUMBER"/>
      <foreign-key foreignTable="CUSTOMER" name="Relation1" onDelete="restrict" onUpdate="cascade">
      <option key="foreignSchemaName" value="XXXX"/>
      <option key="exported" value="false"/>
      <reference foreign="ID" local="CUSTOMER_ID"/>
      </foreign-key>
      <unique name="CUSTOMER_ADDRESS_PK">
      <unique-column name="ID"/>
      </unique>
      </table>

      rest of the code i pasted in my earlier post.
      Last edited by kumarkro; Jun 20th, 2013, 04:41 PM.

      Comment

      Working...
      X