-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with Key
PostPosted: Tue Aug 14, 2007 12:28 pm 
Newbie

Joined: Tue Aug 14, 2007 11:47 am
Posts: 6
Hi,

I'm new in this forum and start using Hibernate recently. I will try to detail my problem the best I can.

First: I have two persistent classes: Page and Category.
Second: Into Page class contains one instance of Category class. See example below.

Code:
   
public class Page {
     private int code;
     private String name;
     private Category category;

    // Getters and setters methods
    ....
  }

  public class Category {
    private int code;
    private String name;
  }


Third: In my database the tables are mapped. Its are working correctly.

This is my context. My problem is when the Page is stored. The table mapped by the Category class are populated with data.

When I try to insert a Page, a key violation happens in Category Class. How I can store a Page using a Category which already exists in database?. Example

Code:
Category cat = new Category();
cat.setCode(500) // Code 500 already exist in database

Page page = new Page();
page.setName("Test Page");
page.setCategory(cat);

HibernateUtil.store(page) //Violation of key here


How can I do it ??
tanks

_________________
Surfing the life!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 11:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@ManyToOne(cascade) is what you're looking for, I guess

_________________
Emmanuel


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

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.