Hibernate SVN: r14396 - in entitymanager/trunk: src/java/org/hibernate/ejb and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-06 15:24:03 -0500 (Thu, 06 Mar 2008)
New Revision: 14396
Added:
entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml
Modified:
entitymanager/trunk/doc/reference/en/modules/configuration.xml
entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java
entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ProgrammaticConfTest.java
Log:
EJB-330 configure(String) now is lazily executed
Modified: entitymanager/trunk/doc/reference/en/modules/configuration.xml
===================================================================
--- entitymanager/trunk/doc/reference/en/modules/configuration.xml 2008-03-06 17:04:50 UTC (rev 14395)
+++ entitymanager/trunk/doc/reference/en/modules/configuration.xml 2008-03-06 20:24:03 UTC (rev 14396)
@@ -434,13 +434,13 @@
<programlisting>Ejb3Configuration cfg = new Ejb3Configuration();
EntityManagerFactory emf =
- cfg.configure("/mypath/hibernate.cfg.xml") //add a regular hibernate.cfg.xml
- .addProperties( properties ) //add some properties
+ cfg.addProperties( properties ) //add some properties
.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
.addRerousce( "mypath/MyOtherCLass.hbm.xml ) //add an hbm.xml file
.addRerousce( "mypath/orm.xml ) //add an EJB3 deployment descriptor
+ .configure("/mypath/hibernate.cfg.xml") //add a regular hibernate.cfg.xml
.buildEntityManagerFactory(); //Create the entity manager factory</programlisting>
</section>
</section>
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java 2008-03-06 17:04:50 UTC (rev 14395)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java 2008-03-06 20:24:03 UTC (rev 14396)
@@ -106,6 +106,7 @@
private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new Ejb3EntityNotFoundDelegate();
private static Configuration DEFAULT_CONFIGURATION = new AnnotationConfiguration();
private String persistenceUnitName;
+ private String cfgXmlResource;
private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
public void handleEntityNotFound(String entityName, Serializable id) {
@@ -960,6 +961,10 @@
preparedProperties.setProperty( Environment.USE_IDENTIFIER_ROLLBACK, "false" );
preparedProperties.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "false" );
preparedProperties.setProperty( HibernatePersistence.DISCARD_PC_ON_CLOSE, "false" );
+ if (cfgXmlResource != null) {
+ preparedProperties.setProperty( HibernatePersistence.CFG_FILE, cfgXmlResource );
+ cfgXmlResource = null;
+ }
//override the new defaults with the user defined ones
//copy programmatically defined properties
@@ -1133,22 +1138,11 @@
}
public Ejb3Configuration configure(String resource) throws HibernateException {
- Thread thread = null;
- ClassLoader contextClassLoader = null;
- if (overridenClassLoader != null) {
- thread = Thread.currentThread();
- contextClassLoader = thread.getContextClassLoader();
- thread.setContextClassLoader( overridenClassLoader );
- }
- try {
- Properties properties = new Properties();
- properties.setProperty( HibernatePersistence.CFG_FILE, resource);
- configure( properties, new HashMap() );
- return this;
- }
- finally {
- if (thread != null) thread.setContextClassLoader( contextClassLoader );
- }
+ //delay the call to configure to allow proper addition of all annotated classes (EJB-330)
+ if (cfgXmlResource != null)
+ throw new PersistenceException("configure(String) method already called for " + cfgXmlResource);
+ this.cfgXmlResource = resource;
+ return this;
}
public Ejb3Configuration addPackage(String packageName) throws MappingException {
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ProgrammaticConfTest.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ProgrammaticConfTest.java 2008-03-06 17:04:50 UTC (rev 14395)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ProgrammaticConfTest.java 2008-03-06 20:24:03 UTC (rev 14396)
@@ -36,6 +36,24 @@
emf.close();
}
+ public void testProgrammaticCfg() throws Exception {
+ Ejb3Configuration conf = new Ejb3Configuration();
+ conf.configure( "org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml" );
+ EntityManagerFactory emf = conf.buildEntityManagerFactory();
+ EntityManager em = emf.createEntityManager();
+ Cat cat = new Cat();
+ cat.setAge( 23 );
+ cat.setDateOfBirth( new Date() );
+ cat.setLength( 32 );
+ cat.setName( "Tomy" );
+ em.getTransaction().begin();
+ em.persist( cat );
+ em.flush();
+ assertNotNull( em.find(Cat.class, cat.getId() ) );
+ em.getTransaction().rollback();
+ emf.close();
+ }
+
protected Properties getProperties() throws IOException {
Properties properties = new Properties( );
InputStream stream = ConfigHelper.getResourceAsStream("/hibernate.properties");
Added: entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml (rev 0)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml 2008-03-06 20:24:03 UTC (rev 14396)
@@ -0,0 +1,9 @@
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+ <mapping class="org.hibernate.ejb.test.Cat"/>
+ </session-factory>
+</hibernate-configuration>
\ No newline at end of file
16 years, 9 months
Hibernate SVN: r14395 - core/trunk/core/src/main/java/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-03-06 12:04:50 -0500 (Thu, 06 Mar 2008)
New Revision: 14395
Modified:
core/trunk/core/src/main/java/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-3111 fixed TM.getStatus() to delegate to getTransaction().getStatus(), or return STATUS_NO_TRANSACTION
Modified: core/trunk/core/src/main/java/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2008-03-06 17:03:03 UTC (rev 14394)
+++ core/trunk/core/src/main/java/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2008-03-06 17:04:50 UTC (rev 14395)
@@ -83,8 +83,8 @@
throw new UnsupportedOperationException();
}
- public int getStatus() throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
+ public int getStatus() throws SystemException {
+ return getTransaction() == null ? Status.STATUS_NO_TRANSACTION : getTransaction().getStatus();
}
public Transaction getTransaction() throws SystemException {
16 years, 9 months
Hibernate SVN: r14394 - core/branches/Branch_3_2/src/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-03-06 12:03:03 -0500 (Thu, 06 Mar 2008)
New Revision: 14394
Modified:
core/branches/Branch_3_2/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-3111 fixed TM.getStatus() to delegate to getTransaction().getStatus(), or return STATUS_NO_TRANSACTION
Modified: core/branches/Branch_3_2/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2008-03-06 16:50:07 UTC (rev 14393)
+++ core/branches/Branch_3_2/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2008-03-06 17:03:03 UTC (rev 14394)
@@ -83,8 +83,8 @@
throw new UnsupportedOperationException();
}
- public int getStatus() throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
+ public int getStatus() throws SystemException {
+ return getTransaction() == null ? Status.STATUS_NO_TRANSACTION : getTransaction().getStatus();
}
public Transaction getTransaction() throws SystemException {
16 years, 9 months
Hibernate SVN: r14393 - in entitymanager/trunk/src: test/org/hibernate/ejb/test/ejb3configuration and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-06 11:50:07 -0500 (Thu, 06 Mar 2008)
New Revision: 14393
Modified:
entitymanager/trunk/src/java/org/hibernate/ejb/EventListenerConfigurator.java
entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ExceptionInterceptor.java
entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/InterceptorTest.java
entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/LocalExceptionInterceptor.java
Log:
EJB-340 onLoad() callback from Interceptor and onLoad() from Lifecycle are never invoked in an EJB3 environment
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/EventListenerConfigurator.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/EventListenerConfigurator.java 2008-03-05 21:57:56 UTC (rev 14392)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/EventListenerConfigurator.java 2008-03-06 16:50:07 UTC (rev 14393)
@@ -46,6 +46,8 @@
import org.hibernate.event.PreLoadEventListener;
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.event.SaveOrUpdateEventListener;
+import org.hibernate.event.def.DefaultPreLoadEventListener;
+import org.hibernate.event.def.DefaultPostLoadEventListener;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.secure.JACCPreDeleteEventListener;
import org.hibernate.secure.JACCPreInsertEventListener;
@@ -101,8 +103,13 @@
new JACCPreDeleteEventListener()
}
);
+
+ //Add the default Hibernate Core PreLoadEventListener
+ //TODO shouldn't we read the value from getPreLoadEventListeners and add JACC?
+ //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
listenerConfig.setPreLoadEventListeners(
new PreLoadEventListener[] {
+ new DefaultPreLoadEventListener(),
new JACCPreLoadEventListener()
}
);
@@ -114,8 +121,11 @@
listenerConfig.setPostInsertEventListeners(
new PostInsertEventListener[] { new EJB3PostInsertEventListener() }
);
+ //Add the default Hibernate Core PostLoadEventListener
+ //TODO shouldn't we read the value from getPostLoadEventListeners
+ //probably a better thing to do as it allows cfg.xml config but this is a big change and need more thoughts
listenerConfig.setPostLoadEventListeners(
- new PostLoadEventListener[] { new EJB3PostLoadEventListener() }
+ new PostLoadEventListener[] { new EJB3PostLoadEventListener(), new DefaultPostLoadEventListener() }
);
listenerConfig.setPostUpdateEventListeners(
new PostUpdateEventListener[] { new EJB3PostUpdateEventListener() }
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ExceptionInterceptor.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ExceptionInterceptor.java 2008-03-05 21:57:56 UTC (rev 14392)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/ExceptionInterceptor.java 2008-03-06 16:50:07 UTC (rev 14393)
@@ -8,92 +8,32 @@
import org.hibernate.EntityMode;
import org.hibernate.Interceptor;
import org.hibernate.Transaction;
+import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
/**
* @author Emmanuel Bernard
*/
-public class ExceptionInterceptor implements Interceptor {
+public class ExceptionInterceptor extends EmptyInterceptor {
public static final String EXCEPTION_MESSAGE = "Interceptor enabled";
+ protected boolean allowSave = false;
- public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ public ExceptionInterceptor() {
+ this.allowSave = false;
}
- public boolean onFlushDirty(
- Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames,
- Type[] types
- ) throws CallbackException {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ public ExceptionInterceptor(boolean allowSave) {
+ this.allowSave = allowSave;
}
- public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
throw new IllegalStateException( EXCEPTION_MESSAGE );
}
- public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
+ if (allowSave) return false;
+ throw new IllegalStateException( EXCEPTION_MESSAGE );
}
-
- public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void preFlush(Iterator entities) throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void postFlush(Iterator entities) throws CallbackException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Boolean isTransient(Object entity) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int[] findDirty(
- Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames,
- Type[] types
- ) {
- return new int[0]; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Object instantiate(String entityName, EntityMode entityMode, Serializable id) throws CallbackException {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getEntityName(Object object) throws CallbackException {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Object getEntity(String entityName, Serializable id) throws CallbackException {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void afterTransactionBegin(Transaction tx) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void beforeTransactionCompletion(Transaction tx) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void afterTransactionCompletion(Transaction tx) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String onPrepareStatement(String sql) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
}
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/InterceptorTest.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/InterceptorTest.java 2008-03-05 21:57:56 UTC (rev 14392)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/InterceptorTest.java 2008-03-06 16:50:07 UTC (rev 14393)
@@ -101,6 +101,30 @@
}
}
+ public void testOnLoadCallInInterceptor() {
+ configuration.setInterceptor( new ExceptionInterceptor(true) );
+ EntityManagerFactory emf = configuration.createEntityManagerFactory();
+ EntityManager em = emf.createEntityManager();
+ Item i = new Item();
+ i.setName( "Laptop" );
+ em.getTransaction().begin();
+ em.persist( i );
+ em.flush();
+ em.clear();
+ try {
+ em.find(Item.class, i.getName() );
+ fail( "No interceptor" );
+ }
+ catch (IllegalStateException e) {
+ assertEquals( ExceptionInterceptor.EXCEPTION_MESSAGE, e.getMessage() );
+ }
+ finally {
+ if ( em.getTransaction() != null && em.getTransaction().isActive() ) em.getTransaction().rollback();
+ em.close();
+ emf.close();
+ }
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[]{
Item.class,
Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/LocalExceptionInterceptor.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/LocalExceptionInterceptor.java 2008-03-05 21:57:56 UTC (rev 14392)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/ejb3configuration/LocalExceptionInterceptor.java 2008-03-06 16:50:07 UTC (rev 14393)
@@ -14,6 +14,7 @@
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
+ if (allowSave) return false;
throw new IllegalStateException( LOCAL_EXCEPTION_MESSAGE );
}
}
16 years, 9 months
Hibernate SVN: r14392 - in annotations/trunk: src/java/org/hibernate/annotations and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-05 16:57:56 -0500 (Wed, 05 Mar 2008)
New Revision: 14392
Modified:
annotations/trunk/build.xml
annotations/trunk/src/java/org/hibernate/annotations/FlushModeType.java
annotations/trunk/src/java/org/hibernate/annotations/NamedNativeQuery.java
annotations/trunk/src/java/org/hibernate/annotations/NamedQuery.java
annotations/trunk/src/java/org/hibernate/cfg/annotations/QueryBinder.java
annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java
annotations/trunk/src/test/org/hibernate/test/annotations/query/QueryAndSQLTest.java
Log:
ANN-700 add the notion of persistence context flush mode to delegate query FM to the PC one
Modified: annotations/trunk/build.xml
===================================================================
--- annotations/trunk/build.xml 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/build.xml 2008-03-05 21:57:56 UTC (rev 14392)
@@ -17,7 +17,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Annotations"/>
<property name="name" value="hibernate-annotations"/>
- <property name="version" value="3.3.1.Beta1"/>
+ <property name="version" value="3.3.1.CR1"/>
<property name="javadoc.packagenames" value="org.hibernate.*"/>
<property name="jdbc.dir" value="jdbc"/>
<property name="copy.test" value="true"/>
Modified: annotations/trunk/src/java/org/hibernate/annotations/FlushModeType.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/annotations/FlushModeType.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/java/org/hibernate/annotations/FlushModeType.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -27,5 +27,10 @@
/**
* see {@link org.hibernate.FlushMode.MANUAL}
*/
- MANUAL
+ MANUAL,
+
+ /**
+ * Current flush mode of the persistence context at the time the query is executed
+ */
+ PERSISTENCE_CONTEXT
}
\ No newline at end of file
Modified: annotations/trunk/src/java/org/hibernate/annotations/NamedNativeQuery.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/annotations/NamedNativeQuery.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/java/org/hibernate/annotations/NamedNativeQuery.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -22,7 +22,7 @@
String resultSetMapping() default ""; // name of SQLResultSetMapping
/** the flush mode for the query */
- FlushModeType flushMode() default FlushModeType.AUTO;
+ FlushModeType flushMode() default FlushModeType.PERSISTENCE_CONTEXT;
/** mark the query as cacheable or not */
boolean cacheable() default false;
/** the cache region to use */
Modified: annotations/trunk/src/java/org/hibernate/annotations/NamedQuery.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/annotations/NamedQuery.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/java/org/hibernate/annotations/NamedQuery.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -21,7 +21,7 @@
/** the Query String for the NamedQuery */
String query();
/** the flush mode for the query */
- FlushModeType flushMode() default FlushModeType.AUTO;
+ FlushModeType flushMode() default FlushModeType.PERSISTENCE_CONTEXT;
/** mark the query as cacheable or not */
boolean cacheable() default false;
/** the cache region to use */
Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/QueryBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/QueryBinder.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/QueryBinder.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -251,6 +251,9 @@
case MANUAL:
flushMode = FlushMode.MANUAL;
break;
+ case PERSISTENCE_CONTEXT:
+ flushMode = null;
+ break;
default:
throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
}
Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/Version.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -8,7 +8,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.3.1.Beta1";
+ public static final String VERSION = "3.3.1.CR1";
private static Log log = LogFactory.getLog( Version.class );
static {
Modified: annotations/trunk/src/test/org/hibernate/test/annotations/query/QueryAndSQLTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/query/QueryAndSQLTest.java 2008-03-05 20:21:13 UTC (rev 14391)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/query/QueryAndSQLTest.java 2008-03-05 21:57:56 UTC (rev 14392)
@@ -374,7 +374,7 @@
@Override
protected String[] getXmlFiles() {
return new String[]{
- "org/hibernate/test/annotations/query/orm.xml"
+ //"org/hibernate/test/annotations/query/orm.xml"
};
}
}
16 years, 10 months
Hibernate SVN: r14391 - entitymanager/trunk/src/java/org/hibernate/ejb/packaging.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-05 15:21:13 -0500 (Wed, 05 Mar 2008)
New Revision: 14391
Modified:
entitymanager/trunk/src/java/org/hibernate/ejb/packaging/ExplodedJarVisitor.java
entitymanager/trunk/src/java/org/hibernate/ejb/packaging/FileZippedJarVisitor.java
entitymanager/trunk/src/java/org/hibernate/ejb/packaging/JarVisitorFactory.java
Log:
EJB-333 space problem in container
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/packaging/ExplodedJarVisitor.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/packaging/ExplodedJarVisitor.java 2008-03-04 22:42:53 UTC (rev 14390)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/packaging/ExplodedJarVisitor.java 2008-03-05 20:21:13 UTC (rev 14391)
@@ -36,12 +36,20 @@
protected void doProcessElements() throws IOException {
File jarFile;
try {
- jarFile = new File( jarUrl.toURI().getSchemeSpecificPart() );
+ String filePart = jarUrl.getFile();
+ if ( filePart != null && filePart.indexOf( ' ' ) != -1 ) {
+ //unescaped (from the container), keep as is
+ jarFile = new File( jarUrl.getFile() );
+ }
+ else {
+ jarFile = new File( jarUrl.toURI().getSchemeSpecificPart() );
+ }
}
catch (URISyntaxException e) {
log.warn( "Malformed url: " + jarUrl, e );
return;
}
+
if ( !jarFile.exists() ) {
log.warn( "Exploded jar does not exists (ignored): " + jarUrl );
return;
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/packaging/FileZippedJarVisitor.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/packaging/FileZippedJarVisitor.java 2008-03-04 22:42:53 UTC (rev 14390)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/packaging/FileZippedJarVisitor.java 2008-03-05 20:21:13 UTC (rev 14391)
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.net.URL;
import java.net.URISyntaxException;
import java.util.Enumeration;
@@ -36,7 +37,14 @@
protected void doProcessElements() throws IOException {
JarFile jarFile;
try {
- jarFile = new JarFile( jarUrl.toURI().getSchemeSpecificPart() );
+ String filePart = jarUrl.getFile();
+ if ( filePart != null && filePart.indexOf( ' ' ) != -1 ) {
+ //unescaped (from the container), keep as is
+ jarFile = new JarFile( jarUrl.getFile() );
+ }
+ else {
+ jarFile = new JarFile( jarUrl.toURI().getSchemeSpecificPart() );
+ }
}
catch (IOException ze) {
log.warn( "Unable to find file (ignored): " + jarUrl, ze );
@@ -46,6 +54,7 @@
log.warn( "Malformed url: " + jarUrl, e );
return;
}
+
if ( entry != null && entry.length() == 1 ) entry = null; //no entry
if ( entry != null && entry.startsWith( "/" ) ) entry = entry.substring( 1 ); //remove '/' header
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/packaging/JarVisitorFactory.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/packaging/JarVisitorFactory.java 2008-03-04 22:42:53 UTC (rev 14390)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/packaging/JarVisitorFactory.java 2008-03-05 20:21:13 UTC (rev 14391)
@@ -1,12 +1,12 @@
//$
package org.hibernate.ejb.packaging;
-import java.net.URL;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
-import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
+import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -50,7 +50,8 @@
}
else if ( "zip".equals( protocol ) //Weblogic has it's own way
|| "code-source".equals( url.getProtocol() ) //OC4J prevent ejb.jar access (ie everything without path)
- || "file".equals( protocol ) ) { //if no wrapping is done
+ || "file".equals( protocol ) //if no wrapping is done
+ ) {
//we have extracted the zip file, so it should be read as a file
if ( file.indexOf( ' ' ) != -1 ) {
//not escaped, need to voodoo
@@ -107,13 +108,21 @@
else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) ) {
File file;
try {
- file = new File( jarUrl.toURI().getSchemeSpecificPart() );
+ final String filePart = jarUrl.getFile();
+ if ( filePart != null && filePart.indexOf( ' ' ) != -1 ) {
+ //unescaped (from the container), keep as is
+ file = new File( jarUrl.getFile() );
+ }
+ else {
+ file = new File( jarUrl.toURI().getSchemeSpecificPart() );
+ }
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
"Unable to visit JAR " + jarUrl + ". Cause: " + e.getMessage(), e
);
}
+
if ( file.isDirectory() ) {
return new ExplodedJarVisitor( jarUrl, filters, entry );
}
16 years, 10 months
Hibernate SVN: r14390 - annotations/trunk/src/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-04 17:42:53 -0500 (Tue, 04 Mar 2008)
New Revision: 14390
Modified:
annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
annotations/trunk/src/java/org/hibernate/cfg/ClassPropertyHolder.java
annotations/trunk/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
annotations/trunk/src/java/org/hibernate/cfg/ComponentPropertyHolder.java
annotations/trunk/src/java/org/hibernate/cfg/PropertyHolder.java
Log:
ANN-650 better exception when @Version is set in an @Embeddable class
Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008-03-04 21:22:12 UTC (rev 14389)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008-03-04 22:42:53 UTC (rev 14390)
@@ -1312,6 +1312,12 @@
+ propertyHolder.getEntityName()
);
}
+ if ( ! propertyHolder.isEntity() ) {
+ throw new AnnotationException(
+ "Unable to define @Version on an embedded class: "
+ + propertyHolder.getEntityName()
+ );
+ }
log.debug( inferredData.getPropertyName() + " is a version property" );
RootClass rootClass = (RootClass) propertyHolder.getPersistentClass();
PropertyBinder propBinder = new PropertyBinder();
Modified: annotations/trunk/src/java/org/hibernate/cfg/ClassPropertyHolder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/ClassPropertyHolder.java 2008-03-04 21:22:12 UTC (rev 14389)
+++ annotations/trunk/src/java/org/hibernate/cfg/ClassPropertyHolder.java 2008-03-04 22:42:53 UTC (rev 14390)
@@ -106,6 +106,10 @@
return false;
}
+ public boolean isEntity() {
+ return true;
+ }
+
public PersistentClass getPersistentClass() {
return persistentClass;
}
Modified: annotations/trunk/src/java/org/hibernate/cfg/CollectionPropertyHolder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2008-03-04 21:22:12 UTC (rev 14389)
+++ annotations/trunk/src/java/org/hibernate/cfg/CollectionPropertyHolder.java 2008-03-04 22:42:53 UTC (rev 14390)
@@ -56,6 +56,10 @@
return false;
}
+ public boolean isEntity() {
+ return false;
+ }
+
public String getEntityName() {
return collection.getOwner().getEntityName();
}
Modified: annotations/trunk/src/java/org/hibernate/cfg/ComponentPropertyHolder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/ComponentPropertyHolder.java 2008-03-04 21:22:12 UTC (rev 14389)
+++ annotations/trunk/src/java/org/hibernate/cfg/ComponentPropertyHolder.java 2008-03-04 22:42:53 UTC (rev 14390)
@@ -91,6 +91,10 @@
return true;
}
+ public boolean isEntity() {
+ return false;
+ }
+
public void setParentProperty(String parentProperty) {
component.setParentProperty( parentProperty );
}
Modified: annotations/trunk/src/java/org/hibernate/cfg/PropertyHolder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/PropertyHolder.java 2008-03-04 21:22:12 UTC (rev 14389)
+++ annotations/trunk/src/java/org/hibernate/cfg/PropertyHolder.java 2008-03-04 22:42:53 UTC (rev 14390)
@@ -30,6 +30,8 @@
boolean isComponent();
+ boolean isEntity();
+
void setParentProperty(String parentProperty);
String getPath();
16 years, 10 months
Hibernate SVN: r14389 - in annotations/trunk/src: test/org/hibernate/test/annotations/manytoone and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-04 16:22:12 -0500 (Tue, 04 Mar 2008)
New Revision: 14389
Added:
annotations/trunk/src/java/org/hibernate/cfg/RecoverableException.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/GenericObject.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Item.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Vendor.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/WarehouseItem.java
annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ZItemCost.java
Modified:
annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
annotations/trunk/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
Log:
ANN-509 recover from Foreign Key Mapping exception when it's due to second pass ordering.
Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-03-04 18:07:28 UTC (rev 14388)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -299,30 +299,35 @@
}
}
caches.clear();
-
- inSecondPass = true;
- processFkSecondPassInOrder();
- Iterator iter = secondPasses.iterator();
- while ( iter.hasNext() ) {
- SecondPass sp = (SecondPass) iter.next();
- //do the second pass of fk before the others and remove them
- if ( sp instanceof CreateKeySecondPass ) {
- sp.doSecondPass( classes );
- iter.remove();
+ try {
+ inSecondPass = true;
+ processFkSecondPassInOrder();
+ Iterator iter = secondPasses.iterator();
+ while ( iter.hasNext() ) {
+ SecondPass sp = (SecondPass) iter.next();
+ //do the second pass of fk before the others and remove them
+ if ( sp instanceof CreateKeySecondPass ) {
+ sp.doSecondPass( classes );
+ iter.remove();
+ }
}
- }
- iter = secondPasses.iterator();
- while ( iter.hasNext() ) {
- SecondPass sp = (SecondPass) iter.next();
- //do the SecondaryTable second pass before any association becasue associations can be built on joins
- if ( sp instanceof SecondaryTableSecondPass ) {
- sp.doSecondPass( classes );
- iter.remove();
+ iter = secondPasses.iterator();
+ while ( iter.hasNext() ) {
+ SecondPass sp = (SecondPass) iter.next();
+ //do the SecondaryTable second pass before any association becasue associations can be built on joins
+ if ( sp instanceof SecondaryTableSecondPass ) {
+ sp.doSecondPass( classes );
+ iter.remove();
+ }
}
+ super.secondPassCompile();
+ inSecondPass = false;
}
- super.secondPassCompile();
- inSecondPass = false;
+ catch (RecoverableException e) {
+ //the exception was not recoverable after all
+ throw (RuntimeException) e.getCause();
+ }
Iterator tables = tableUniqueConstraints.entrySet().iterator();
Table table;
Map.Entry entry;
@@ -476,10 +481,34 @@
while ( it.hasNext() ) {
( (SecondPass) it.next() ).doSecondPass( classes );
}
- it = endOfQueueFkSecondPasses.listIterator();
- while ( it.hasNext() ) {
- ( (SecondPass) it.next() ).doSecondPass( classes );
+
+ /*
+ * If a second pass raises a recoverableException, queue it for next round
+ * stop of no pass has to be processed or if the number of pass to processes
+ * does not diminish between two rounds.
+ * If some failing pass remain, raise the original exception
+ */
+ boolean stopProcess = false;
+ RuntimeException originalException = null;
+ while ( ! stopProcess ) {
+ List failingSecondPasses = new ArrayList();
+ it = endOfQueueFkSecondPasses.listIterator();
+ while ( it.hasNext() ) {
+ final SecondPass pass = (SecondPass) it.next();
+ try {
+ pass.doSecondPass( classes );
+ }
+ catch (RecoverableException e) {
+ failingSecondPasses.add( pass );
+ if (originalException == null) originalException = (RuntimeException) e.getCause();
+ }
+ }
+ stopProcess = failingSecondPasses.size() == 0 || failingSecondPasses.size() == endOfQueueFkSecondPasses.size();
+ endOfQueueFkSecondPasses = failingSecondPasses;
}
+ if (endOfQueueFkSecondPasses.size() > 0) {
+ throw originalException;
+ }
}
}
Modified: annotations/trunk/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2008-03-04 18:07:28 UTC (rev 14388)
+++ annotations/trunk/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -391,11 +391,16 @@
referencedEntity, columns[0].getReferencedColumn(), mappings
);
if ( columnOwner == null ) {
- throw new MappingException(
- "Unable to find column with logical name: "
- + columns[0].getReferencedColumn() + " in " + referencedEntity.getTable() + " and its related "
- + "supertables and secondary tables"
- );
+ try {
+ throw new MappingException(
+ "Unable to find column with logical name: "
+ + columns[0].getReferencedColumn() + " in " + referencedEntity.getTable() + " and its related "
+ + "supertables and secondary tables"
+ );
+ }
+ catch (MappingException e) {
+ throw new RecoverableException(e);
+ }
}
Table matchingTable = columnOwner instanceof PersistentClass ?
( (PersistentClass) columnOwner ).getTable() :
Added: annotations/trunk/src/java/org/hibernate/cfg/RecoverableException.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/RecoverableException.java (rev 0)
+++ annotations/trunk/src/java/org/hibernate/cfg/RecoverableException.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,25 @@
+//$
+package org.hibernate.cfg;
+
+import org.hibernate.AnnotationException;
+
+/**
+ * Should neven be exposed to the client
+ * An exception that wrap an underlying exception whith the hope
+ * subsequent processing will recover from it.
+ *
+ * @author Emmanuel Bernard
+ */
+public class RecoverableException extends AnnotationException {
+ public RecoverableException(String msg, Throwable root) {
+ super( msg, root );
+ }
+
+ public RecoverableException(Throwable root) {
+ super( root );
+ }
+
+ public RecoverableException(String s) {
+ super( s );
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/GenericObject.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/GenericObject.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/GenericObject.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,68 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.io.Serializable;
+import java.rmi.server.UID;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Transient;
+import javax.persistence.Version;
+
+@MappedSuperclass
+public class GenericObject implements Serializable {
+ protected int id;
+ protected int version;
+ protected UID uid = new UID();
+
+ @Id
+ @GeneratedValue( strategy = GenerationType.IDENTITY )
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Version
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public void incrementVersion() {
+ this.version++;
+ }
+
+ public boolean equals(Object other) {
+ if ( this == other )
+ return true;
+ if ( ( other == null ) || !( other.getClass().equals( this.getClass() ) ) )
+ return false;
+ GenericObject anObject = (GenericObject) other;
+ if ( this.id == 0 || anObject.id == 0 )
+ return false;
+
+ return ( this.id == anObject.id );
+ }
+
+ public int hashCode() {
+ if ( this.id == 0 )
+ return super.hashCode();
+ return this.id;
+ }
+
+ @Transient
+ public UID getUid() {
+ return uid;
+ }
+
+ public void setUid(UID uid) {
+ this.uid = uid;
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Item.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Item.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Item.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,13 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Transient;
+
+
+@Entity
+public class Item extends GenericObject {
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,45 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.math.BigDecimal;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.Session;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ManyToOneReferencedColumnNameTest extends TestCase {
+ public void testReoverableExceptionInFkOrdering() throws Exception {
+ //SF should not blow up
+ Vendor v = new Vendor();
+ Item i = new Item();
+ ZItemCost ic = new ZItemCost();
+ ic.setCost( new BigDecimal(2) );
+ ic.setItem( i );
+ ic.setVendor( v );
+ WarehouseItem wi = new WarehouseItem();
+ wi.setDefaultCost( ic );
+ wi.setItem( i );
+ wi.setVendor( v );
+ wi.setQtyInStock( new BigDecimal(2) );
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.save( i );
+ s.save( v );
+ s.save( ic );
+ s.save( wi );
+ s.flush();
+ s.getTransaction().rollback();
+ s.close();
+
+ }
+ protected Class[] getMappings() {
+ return new Class[] {
+ Item.class,
+ Vendor.class,
+ WarehouseItem.class,
+ ZItemCost.class
+ };
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Vendor.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Vendor.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/Vendor.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,12 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Transient;
+
+@Entity
+public class Vendor extends GenericObject {
+}
\ No newline at end of file
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/WarehouseItem.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/WarehouseItem.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/WarehouseItem.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,62 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.math.BigDecimal;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class WarehouseItem extends GenericObject {
+
+
+ Item item;
+ Vendor vendor;
+ ZItemCost defaultCost;
+ BigDecimal qtyInStock;
+
+
+ public BigDecimal getQtyInStock() {
+ return qtyInStock;
+ }
+
+ public void setQtyInStock(BigDecimal qtyInStock) {
+ this.qtyInStock = qtyInStock;
+ }
+
+ @ManyToOne
+//(fetch=FetchType.LAZY)
+ @JoinColumn( name = "ITEM_ID", unique = false, nullable = false, insertable = true, updatable = true )
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ @ManyToOne( fetch = FetchType.LAZY )
+ @JoinColumn( name = "VENDOR_ID", unique = false, nullable = false, insertable = true, updatable = true )
+ public Vendor getVendor() {
+ return vendor;
+ }
+
+ public void setVendor(Vendor vendor) {
+ this.vendor = vendor;
+ }
+
+ @ManyToOne
+ @JoinColumns( {
+ @JoinColumn( name = "vendor_id", referencedColumnName = "vendor_id", insertable = false, updatable = false ),
+ @JoinColumn( name = "item_id", referencedColumnName = "item_id", insertable = false, updatable = false )
+ } )
+ public ZItemCost getDefaultCost() {
+ return defaultCost;
+ }
+
+ public void setDefaultCost(ZItemCost defaultCost) {
+ this.defaultCost = defaultCost;
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ZItemCost.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ZItemCost.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/manytoone/referencedcolumnname/ZItemCost.java 2008-03-04 21:22:12 UTC (rev 14389)
@@ -0,0 +1,46 @@
+//$
+package org.hibernate.test.annotations.manytoone.referencedcolumnname;
+
+import java.math.BigDecimal;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
+import javax.persistence.Transient;
+import javax.persistence.JoinColumn;
+
+@Entity
+public class ZItemCost extends GenericObject {
+
+ Item item;
+ Vendor vendor;
+ BigDecimal cost;
+
+ @ManyToOne( fetch = FetchType.LAZY )
+ //@JoinColumn(name="ITEM_ID", unique=false, nullable=false, insertable=true, updatable=true)
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ @ManyToOne( fetch = FetchType.LAZY )
+ //@JoinColumn(name="VENDOR_ID", unique=false, nullable=false, insertable=true, updatable=true)
+ public Vendor getVendor() {
+ return vendor;
+ }
+
+ public void setVendor(Vendor vendor) {
+ this.vendor = vendor;
+ }
+
+ public BigDecimal getCost() {
+ return cost;
+ }
+
+ public void setCost(BigDecimal cost) {
+ this.cost = cost;
+ }
+}
+
16 years, 10 months
Hibernate SVN: r14388 - in annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement: deepcollectionelements and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-04 13:07:28 -0500 (Tue, 04 Mar 2008)
New Revision: 14388
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/
annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java
annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java
annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/C.java
annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java
Log:
ANN-591 tests
Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java 2008-03-04 18:07:28 UTC (rev 14388)
@@ -0,0 +1,45 @@
+//$
+package org.hibernate.test.annotations.collectionelement.deepcollectionelements;
+
+/**
+ * @author Emmanuel Bernard
+ */
+
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.IndexColumn;
+
+@Entity
+@Table( name = "A" )
+public class A {
+ @Id
+ @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "aSequence" )
+ @SequenceGenerator( name = "aSequence", sequenceName = "seq_A" )
+ private int id;
+ @CollectionOfElements
+ @IndexColumn( name = "ndx" )
+ private List<B> listOfB;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public List<B> getListOfB() {
+ return listOfB;
+ }
+
+ public void setListOfB(List<B> listOfB) {
+ this.listOfB = listOfB;
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java 2008-03-04 18:07:28 UTC (rev 14388)
@@ -0,0 +1,36 @@
+//$
+package org.hibernate.test.annotations.collectionelement.deepcollectionelements;
+
+import java.util.List;
+import javax.persistence.Embeddable;
+import javax.persistence.Transient;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.IndexColumn;
+
+@Embeddable
+public class B {
+ private String name;
+
+ //@CollectionOfElements
+ @OneToMany
+ @IndexColumn( name = "ndx" )
+ private List<C> listOfC;
+
+ public List<C> getListOfC() {
+ return listOfC;
+ }
+
+ public void setListOfC(List<C> listOfC) {
+ this.listOfC = listOfC;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/C.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/C.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/C.java 2008-03-04 18:07:28 UTC (rev 14388)
@@ -0,0 +1,27 @@
+//$
+package org.hibernate.test.annotations.collectionelement.deepcollectionelements;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
+
+@Entity
+public class C {
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Column( length = 500 )
+ private String comment;
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+}
Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java 2008-03-04 18:07:28 UTC (rev 14388)
@@ -0,0 +1,25 @@
+//$
+package org.hibernate.test.annotations.collectionelement.deepcollectionelements;
+
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+
+//TEST not used: wait for ANN-591 and HHH-3157
+public class DeepCollectionElementTest extends TestCase {
+
+ public void testInitialization() throws Exception {
+ //test only the SF creation
+
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ //A.class,
+ //B.class,
+ //C.class
+ };
+ }
+}
16 years, 10 months
Hibernate SVN: r14387 - annotations/trunk/src/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-03-03 23:17:10 -0500 (Mon, 03 Mar 2008)
New Revision: 14387
Modified:
annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
Log:
ANN-690 allow chaining invoke in AnnotationConfiguration
Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-03-04 03:52:43 UTC (rev 14386)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2008-03-04 04:17:10 UTC (rev 14387)
@@ -20,6 +20,7 @@
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
+import java.net.URL;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
@@ -35,6 +36,7 @@
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
+import org.hibernate.Interceptor;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
@@ -711,7 +713,7 @@
}
@Override
- public Configuration addInputStream(InputStream xmlInputStream) throws MappingException {
+ public AnnotationConfiguration addInputStream(InputStream xmlInputStream) throws MappingException {
try {
List errors = new ArrayList();
SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, getEntityResolver() );
@@ -828,7 +830,168 @@
return super.buildSessionFactory();
}
+ @Override
+ public AnnotationConfiguration addFile(String xmlFile) throws MappingException {
+ super.addFile( xmlFile );
+ return this;
+ }
+ @Override
+ public AnnotationConfiguration addFile(File xmlFile) throws MappingException {
+ super.addFile( xmlFile );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addCacheableFile(File xmlFile) throws MappingException {
+ super.addCacheableFile( xmlFile );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addCacheableFile(String xmlFile) throws MappingException {
+ super.addCacheableFile( xmlFile );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addXML(String xml) throws MappingException {
+ super.addXML( xml );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addURL(URL url) throws MappingException {
+ super.addURL( url );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addResource(String resourceName, ClassLoader classLoader) throws MappingException {
+ super.addResource( resourceName, classLoader );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addDocument(org.w3c.dom.Document doc) throws MappingException {
+ super.addDocument( doc );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addResource(String resourceName) throws MappingException {
+ super.addResource( resourceName );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addClass(Class persistentClass) throws MappingException {
+ super.addClass( persistentClass );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addJar(File jar) throws MappingException {
+ super.addJar( jar );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addDirectory(File dir) throws MappingException {
+ super.addDirectory( dir );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setInterceptor(Interceptor interceptor) {
+ super.setInterceptor( interceptor );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setProperties(Properties properties) {
+ super.setProperties( properties );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration addProperties(Properties extraProperties) {
+ super.addProperties( extraProperties );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration mergeProperties(Properties properties) {
+ super.mergeProperties( properties );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setProperty(String propertyName, String value) {
+ super.setProperty( propertyName, value );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration configure() throws HibernateException {
+ super.configure();
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration configure(String resource) throws HibernateException {
+ super.configure( resource );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration configure(URL url) throws HibernateException {
+ super.configure( url );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration configure(File configFile) throws HibernateException {
+ super.configure( configFile );
+ return this;
+ }
+
+ @Override
+ protected AnnotationConfiguration doConfigure(InputStream stream, String resourceName) throws HibernateException {
+ super.doConfigure( stream, resourceName );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration configure(org.w3c.dom.Document document) throws HibernateException {
+ super.configure( document );
+ return this;
+ }
+
+ @Override
+ protected AnnotationConfiguration doConfigure(Document doc) throws HibernateException {
+ super.doConfigure( doc );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy) throws MappingException {
+ super.setCacheConcurrencyStrategy( clazz, concurrencyStrategy );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy) throws MappingException {
+ super.setCollectionCacheConcurrencyStrategy( collectionRole, concurrencyStrategy );
+ return this;
+ }
+
+ @Override
+ public AnnotationConfiguration setNamingStrategy(NamingStrategy namingStrategy) {
+ super.setNamingStrategy( namingStrategy );
+ return this;
+ }
+
//not a public API
public ReflectionManager getReflectionManager() {
return reflectionManager;
16 years, 10 months