-->
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.  [ 4 posts ] 
Author Message
 Post subject: EntityManager.merge throwing IllegalArgumentException
PostPosted: Mon Sep 25, 2006 5:00 pm 
Newbie

Joined: Mon Sep 25, 2006 4:44 pm
Posts: 4
Hibernate version:
16:42:40,695 INFO Version:15 - Hibernate EntityManager 3.2.0.CR2
16:42:40,742 INFO Version:15 - Hibernate Annotations 3.2.0.CR2
16:42:40,773 INFO Environment:500 - Hibernate 3.2 cr4


I am trying to attempt optimistic locking with the EntityManager.

When the EntityManager detects a change, it is throwing the following stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: id to load is required for loading
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:792)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)

If I change the code to use a SessionFactory and session instead of using EntityManager it works correctly.

I am configuring the EntityManager with the following code:
Ejb3Configuration cfg = new Ejb3Configuration();


EntityManagerFactory emf =
cfg.configure("com/hibernate/test/hibernate.cfg.xml")
.buildEntityManagerFactory();


My code to persist the changes is:
private static void updateUser(EntityManagerFactory enf, HibernateUser user)
{
EntityManager em = enf.createEntityManager();
EntityTransaction t = em.getTransaction();


try {
t.begin();
try
{
em.merge(user);
t.commit();
}
catch (RuntimeException re)
{
t.rollback();
throw re;
}
}
finally
{
em.close();
}
}


My simple hello world class is
package com.hibernate.test;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;



@javax.persistence.SequenceGenerator(
name="SEQ_GEN",
sequenceName="BATCHID_SEQ",
allocationSize=1
)

@Entity
@Table(name="Hibernate")
public class HibernateUser
{
private Long id;
private String name;
private Long version;

public HibernateUser()
{
super();
}

@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}

@Basic
public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

@Version
public Long getVersion()
{
return version;
}
public void setVersion(Long version)
{
this.version = version;
}



}

Do I have something configured wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it should work, you probably have some weird mistake somewhere

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 3:53 pm 
Newbie

Joined: Mon Sep 25, 2006 4:44 pm
Posts: 4
I can't find anything wrong with my configuration. Could this possibly be a bug? The reason I ask is because it looks the EntityManager is catching
the concurrent modification because it is about to throw a PersistenceException. However, it looks like its creating a LoadEvent and passing in a null Id to the LoadEvent constructor which is what throws the exception.


at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:792)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah got it.
http://opensource.atlassian.com/projects/hibernate/browse/EJB-231

The original exception is an optimistic locking exception, I swallow it by mistake

Thanks

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.