-->
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: Foreign Key as Primary Key and cascaded persistence
PostPosted: Wed May 02, 2012 7:35 am 
Newbie

Joined: Wed May 02, 2012 7:25 am
Posts: 1
Hi all,

I have problem with cascading persistence with the following code consisting of 2 annotated classes Listing and ListingLocation.
if a Listing instance is set to the listing2 of a ListingLocation instance, the Listing instance will be automatically persisted when I save the ListingLocation instance
if a Listing instance is only set to the listing1 of a ListingLocation instance, the Listing instance will NOT be automatically persisted when I save the ListingLocation instance
listing1 is also used as the primary and foreign key.

Would any one please tell me how should I code to get listing1 to automatically get persisted?

Thank you very much.

Code:
@Entity
@Table
@Access(AccessType.FIELD)
public class Listing implements Serializable {
@Id
@GeneratedValue
private long id;
@Column(columnDefinition = "DECIMAL(10,2)")
private double price;
...}


Code:
@Entity
@Table
@Access(AccessType.FIELD)
public class ListingLocation implements Serializable {
  @Id
          @OneToOne()
          @Cascade(value={ CascadeType.PERSIST, CascadeType.SAVE_UPDATE })
          @ForeignKey(name = "FK_ID")
          @JoinColumn(name = "ID", referencedColumnName = "id", unique = true, updatable = false, insertable = false)
          private Listing listing1;
      @Column(name = "address")
          private String address;
      @OneToOne()
          @Cascade(value={ CascadeType.PERSIST, CascadeType.SAVE_UPDATE })
          @JoinColumn(name = "List2", referencedColumnName = "id", nullable = true)
          private Listing listing2;
...}


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.