Author: epbernard Date: 2006-04-26 19:23:48 -0400 (Wed, 26 Apr 2006) New Revision: 9804 Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/Music.java Modified: trunk/HibernateExt/ejb/doc/reference/en/master.xml trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java Log: EJB-166 and docs Modified: trunk/HibernateExt/ejb/doc/reference/en/master.xml =================================================================== --- trunk/HibernateExt/ejb/doc/reference/en/master.xml 2006-04-26 23:20:18 UTC (rev 9803) +++ trunk/HibernateExt/ejb/doc/reference/en/master.xml 2006-04-26 23:23:48 UTC (rev 9804) @@ -16,7 +16,7 @@ <subtitle>User guide</subtitle> - <releaseinfo>3.1 beta 7</releaseinfo> + <releaseinfo>3.1.0 beta 8</releaseinfo> <mediaobject> <imageobject> @@ -60,5 +60,4 @@ &query-ejbql; &native; - </book> \ No newline at end of file Modified: trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml =================================================================== --- trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml 2006-04-26 23:20:18 UTC (rev 9803) +++ trunk/HibernateExt/ejb/doc/reference/en/modules/configuration.xml 2006-04-26 23:23:48 UTC (rev 9804) @@ -8,8 +8,8 @@ <para>The EJB3 compatible Hibernate EntityManager is built on top of Hibernate core and Hibernate Annotations. You have to use compatible versions of each module. This version is known to work on Hibernate - 3.2.0.CR2 and Hibernate Annotations 3.1beta9. The following libraries have - to be in your classpath: hibernate3.jar, hibernate-annotations.jar, + 3.2.0.CR2 and Hibernate Annotations 3.1.0.Beta10. The following libraries + have to be in your classpath: hibernate3.jar, hibernate-annotations.jar, hibernate-entity-manager.jar and all needed third party libraries for each package.(incl. ejb-persistence.jar).</para> </section> @@ -122,8 +122,13 @@ <listitem> <para>The class element specifies a EJB3 compliant XML mapping - file that you will map. This feature is currently not - supported.</para> + file that you will map. The file has to be in the classpath. As + per the EJB3 specification, Hibernate EntityManager will try to + load the mapping file located in the jar file at + <literal>META_INF/orm.xml</literal>. Of course any explicit + mapping file will be loaded too. As a matter of fact, you can + provides any XML file in the mapping file element ie. either hbm + files or EJB3 deployment descriptor.</para> </listitem> </varlistentry> @@ -422,7 +427,8 @@ .setInterceptor( myInterceptorImpl ) // set an interceptor .addAnnotatedClass( MyAnnotatedClass.class ) //add a class to be mapped .addClass( NonAnnotatedClass.class ) //add an hbm.xml file using the Hibernate convention - .addFile( "/mypath/MyOtherCLass.hbm.xml ) //add an hbm.xml file + .addRerousce( "mypath/MyOtherCLass.hbm.xml ) //add an hbm.xml file + .addRerousce( "mypath/orm.xml ) //add an EJB3 deployment descriptor .createEntityManagerFactory(); //Create the entity manager factory</programlisting> </section> </section> Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-04-26 23:20:18 UTC (rev 9803) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-04-26 23:23:48 UTC (rev 9804) @@ -37,7 +37,6 @@ import org.hibernate.ObjectNotFoundException; import org.hibernate.SQLQuery; import org.hibernate.Session; -import org.hibernate.StaleObjectStateException; import org.hibernate.StaleStateException; import org.hibernate.Transaction; import org.hibernate.UnresolvableObjectException; @@ -201,9 +200,6 @@ try { return (A) getSession().merge( entity ); } - catch (StaleObjectStateException sse) { - throw new IllegalArgumentException( sse ); - } catch (ObjectDeletedException sse) { throw new IllegalArgumentException( sse ); } Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2006-04-26 23:20:18 UTC (rev 9803) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2006-04-26 23:23:48 UTC (rev 9804) @@ -0,0 +1,52 @@ +//$Id: $ +package org.hibernate.ejb.test.exception; + +import javax.persistence.EntityManager; +import javax.persistence.OptimisticLockException; + +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class ExceptionTest extends TestCase { + + public void testOptimisticLockingException() throws Exception { + EntityManager em = factory.createEntityManager(); + EntityManager em2 = factory.createEntityManager(); + em.getTransaction().begin(); + Music music = new Music(); + music.setName( "Old Country" ); + em.persist( music ); + em.getTransaction().commit(); + + em2.getTransaction().begin(); + Music music2 = em2.find( Music.class, music.getId() ); + music2.setName( "HouseMusic" ); + em2.getTransaction().commit(); + em2.close(); + + em.getTransaction().begin(); + music.setName( "Rock" ); + try { + em.flush(); + fail("Should raise an optimistic lock exception"); + } + catch( OptimisticLockException e) { + //success + } + catch( Exception e ) { + fail("Should raise an optimistic lock exception"); + } + finally { + em.getTransaction().rollback(); + em.close(); + } + } + + public Class[] getAnnotatedClasses() { + return new Class[] { + Music.class + }; + } +} Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/Music.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/Music.java 2006-04-26 23:20:18 UTC (rev 9803) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/exception/Music.java 2006-04-26 23:23:48 UTC (rev 9804) @@ -0,0 +1,41 @@ +//$Id: $ +package org.hibernate.ejb.test.exception; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.GeneratedValue; +import javax.persistence.Version; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class Music { + private Integer id; + private Integer version; + private String name; + + @Id @GeneratedValue public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Version public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } +} |