-->
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: How to have an implicit @Id ?
PostPosted: Sun Dec 24, 2006 12:38 pm 
Newbie

Joined: Sun Dec 24, 2006 12:16 pm
Posts: 1
Hi,

I have some POJO's classes that I want to persist. Most of them need to be saved as an @Entity since their instances need to be shared by some objects and not simply duplicated.

But for most of them I don't want to add them a field specially for the primary key (@Id) because those object won't be queried by the users via their primary key but via their reference in other objects, and because I want my POJO to stay POJO.

In other words, here is what I have now :

@Entity
public class GameEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long id;

// Some instances of Color are shared between the game entities.
public Color color;
}

@Entity
public class Color implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id; // I don't need/want that field my Java class !!!! :-(

public float r;
public float g;
public float b;
}


And here is what I would have, an implicit @id field that is not defined in my POJO class:

@Entity
@ImplicitId(type="long", name="id") // ... something like that
public class Color implements Serializable {
public float r;
public float g;
public float b;
}

... where the field "id" is in the DB but not in the class of my entity, and where the entity manager keep track himself of the key of my color instances with a kind of Map<PojoObject, PojoKey>. In this way, the primary key is not invasive in my POJO code.

Is it possible ? How ?

Regards,
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 11:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can use hbm.xml to write such entity without an id property. But we have more or less deprecated this usage in Hibernate. This was mostly useless and not used. And you can't use all the feature set of Hibernate (detached objects etc)

_________________
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.