-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: do the correct referencing
PostPosted: Tue Mar 02, 2004 8:51 am 
Newbie

Joined: Mon Mar 01, 2004 3:29 am
Posts: 3
Hi,

I'm really new to hibernate and reading the mapping docu and some threads in here doesn't helped me. I have the problem with referencing a table. So I'm considering what goes wrong: Is that the association type or do I used the association wrong ?

In the end I want following:

Code:
CREATE TABLE REGULAR_PAYMENT (
    REGID           INTEGER NOT NULL,
    DAY_OF_PAYMENT  INTEGER NOT NULL,
    PAYMENT_CYCLE   INTEGER NOT NULL,
    GROUPID         INTEGER NOT NULL,
    DBCR            INTEGER NOT NULL,
    LAST_EXECUTION  DATE,
    NAME            VARCHAR(70) NOT NULL,
    PRIMARY KEY (REGID),
    UNIQUE (NAME, GROUPID, DBCR),
    FOREIGN KEY (GROUPID) REFERENCES PAYMENTGROUP
);


Code:
CREATE TABLE PAYMENTGROUP (
    GROUPID  INTEGER NOT NULL,
    NAME     VARCHAR(70) NOT NULL
);


As seen above the table PAYMENTGROUP is refernced by the table REGULAR_PAYMENT. That's it. The values in the table PAYMENTGROUP only are to be used from this and additional tables. Keep the table design in mind I made following mappings:


Code:
   
<hibernate-mapping>
  <class name="com.cando.budget.db.RegularPayment" table="REGULAR_PAYMENT">
    <id name="regId" type="integer" column="REGID">
      <generator class="sequence">
        <param name="sequence">regular_payment_gen</param>
      </generator>
    </id>
       
    <property name="dayOfPayment" column="DAY_OF_PAYMENT" not-null="true" />

    <property name="paymentCycle" column="PAYMENT_CYCLE" not-null="true" />

    <one-to-one name="group" class="com.cando.budget.db.PaymentGroup" constrained="false"/>
   
    <property name="dbcr" column="DBCR" not-null="true" unique="true" />

    <property name="lastExecution" column="LAST_EXECUTION" not-null="false"/>

    <property name="name" column="NAME" not-null="true" unique="true" />
  </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
  <class name="com.cando.budget.db.PaymentGroup" table="PaymentGroup">
       
    <id name="groupId" type="integer" column="GROUPID">
      <generator class="sequence">
        <param name="sequence">group_gen</param>
      </generator>
    </id>
       
    <property name="name" type="string" column="NAME" not-null="true" unique="true"/>
   
  </class>
</hibernate-mapping>


To save a RegularPayment I used following code:

Code:
// adding some PaymentGroup entries done already ...

// create a regular payment with an existing reference to PaymentGroup
transaction = session.beginTransaction();

List group = session.find("from PaymentGroup where name='Gehalt'");
if (group.size() == 1){
  RegularPayment reg = new RegularPayment(0, "Gehalt Rico", (PaymentGroup)group.get(0), 2);
  session.save(reg);
}

transaction.commit();


On the console now I get the error:

Code:
[java] net.sf.hibernate.HibernateException: identifier of an instance of com.cando.budget.db.RegularPayment altered from 12 to 12


Who can help ? How can I do it right ?

Thanks in forward
Rico


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.