-->
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: Without composite id?
PostPosted: Thu Oct 26, 2006 5:15 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Hi to all,
sorry for this stupid question.
I have read into Hibernate ref docs, "....We call this approach an embedded composite identifier, and discourage it for serious applications."
I have need some info about this concept about hibernate primary key and surrogation key.
I have no legacy schema for my new application but i'm very confuse how to use hibernate without composite id.
For example this scenario.
Inovice and ListItemInvoice (of the invoice)
How "can i see" a invoice without composite id? For me a primary key it's
year, progressive number. and for ListItemInvoice (year,progr, number row).
But in all internet hibernate example using a surrogate key
Can you help me to understand how to map and create this scenario in hibernate? I'm very confusing about this.
I have understand this now:
1)I must create my tables with one field as primary key?
But how i can use Hibernate (save or SaveOrUpdate, update etc) if Hibernate check my primary key by one id? I wish that hibernate consider that my key is
year progr etc.. I must use composite id? Ok i have read that this is a Business Logic Key. Can you give me some example or link about this.
Sorry for my english i hope that you have understand my problem
Devis
Italy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:45 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
I thin'k to use my business key in this way but don't work
hibernate don't insert and don't update where are i wrong?
Pls help me
Devis

Code:
CREATE TABLE user (

   id integer NOT NULL,  -- values generated from user_id_seq

   email varchar(128) NOT NULL,

   passwd varchar(128) NOT NULL

);
CREATE SEQUENCE user_id_seq;




public class User {

   private Long id;

   private String email;

   private String password;



   public Long getId() { return id; }

   @SuppressWarnings("unused")

   private void setId(Long i) { id = i; }



   public String getEmail() { return email; }

   public void setEmail(String e) { email = e; }



   public String getPassword() { return password; }

   public void setPassword(String p) { password = p; }



   public int hashCode() {

      return email.hashCode();

   }

   public boolean equals(Object obj) {

      if (this == obj) return true;

      if (!(obj instanceof User)) return false;

      final User that = (User) obj;

      return email.equals(that.getEmail());

   }

}




<hibernate-mapping>

   <class name="User" table="user">

   <id name="id">

   <generator class="sequence">
<param name="sequence">user_id_seq</param>
</generator>
</id>
<property name="email"/>
<property name="password" column="passwd"/>
</class>
</hibernate-mapping>



Dao Class


                        TblUtentiDAO ex = new TblUtentiDAO();
         User vo = new User()
         vo.setEmail("mario@italia.it");
         vo.setDescr("ciao");
         
         ex.SaveOrUpdate(vo);
         ex.getSession().Close();








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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.