Hi!
Many of my entities have an id of type long. So I put the code (getters,
setters ...) into an superclass. After I did it, the id wasn't initialized by
hibernate any more, if I persisted an entity. Thats very strange.
Here is the code:
| public class GenerateValueTestcase extends TestCase {
|
| @MappedSuperclass
| public static abstract class EntityWithIntId {
|
| private long id = -1;
|
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| public long getId() {
| return id;
| }
|
| public void setId(long id) {
| this.id = id;
| }
| }
|
| @Entity
| public static class TestEntity extends EntityWithIntId implements
Serializable {
|
| private static final long serialVersionUID = 1L;
|
| }
|
| public void testGeneratedIds() {
|
| TestStarterRemote bean = UsefullFunctions.getTestStarterRemote();
|
| Set<Long> ids = new HashSet<Long>();
|
| final int NO_ENTITIES = 10;
|
| for (int i = 0; i < NO_ENTITIES; i++) {
| EntityWithIntId entity = new TestEntity();
| entity = bean.merge(entity);
| ids.add(entity.getId());
| }
|
| assertEquals("Each entity must have an unique id", NO_ENTITIES, ids
| .size());
|
| }
|
| }
|
The bean.merge method:
| public <T> T merge(T o) {
| return entityManager.merge(o);
| }
|
Any ideas or workarounds? Copying the code into each class is not the best idea
I think....
Thanks for your help
Meinert
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3986474#3986474
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3986474
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user