-->
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: Auto saving OnetoOne association with annotations
PostPosted: Thu Aug 20, 2009 12:58 am 
Newbie

Joined: Thu Aug 20, 2009 12:54 am
Posts: 1
Hi, I am a hibernate newbie

I have a member and a member card no table the card no table belongs to the member table. The foreign key in this table is on the CUSTNO column.

I am reading the variables in from action beans in stripes and have a bunch of member and credit card properties

like
member.name
member.address

and
member.memberCreditCard.lastDigits
member.memberCreditCard.expiry

when I use the

Code:
memberDao.save(member);
memberDao.commit();

it gives me an error on commit saying that the memberCreditCard table's member id field (CUSTNO) is blank

java.sql.SQLException: ORA-01400: cannot insert NULL into ("DB"."TM_CUSTCC"."CUSTNO")

does anyone know how I can get hibernate to autosave this value?

I am using hibernate version 3.2.5

The Member class
Code:
@Entity
@Table(name="TM_CUST")
public class Member{
        @GenericGenerator(name="generator", strategy="increment")
        @Id @GeneratedValue(generator="generator")
        @Column(name="CUSTNO")
        private int no;

        @OneToOne(mappedBy="member", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        private MemberCreditCard memberCreditCard;

        public void setMemberCreditCard(MemberCreditCard memberCreditCard) {
                this.memberCreditCard = memberCreditCard;
        }

        public MemberCreditCard getMemberCreditCard() {
                return memberCreditCard;
        }
}


The credit card class
Code:
@Entity
@Table(name="TM_CUSTCC")
public class MemberCreditCard{
       @ManyToOne
        @JoinColumn(name="CUSTNO")
        private Member member;
       
        public Member getMember() {
                return member;
        }

        public void setMember(Member member) {
                this.member = member;
        }
}

Many thanks for your help

Richard


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.