Author: epbernard
Date: 2009-12-10 10:27:00 -0500 (Thu, 10 Dec 2009)
New Revision: 18198
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
Log:
HHH-4665 PersistenceUnitUtil.getIdentifier()
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-12-10
14:40:53 UTC (rev 18197)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-12-10
15:27:00 UTC (rev 18198)
@@ -35,6 +35,10 @@
import javax.persistence.spi.LoadState;
import org.hibernate.SessionFactory;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.EntityMode;
+import org.hibernate.metadata.ClassMetadata;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.cfg.Configuration;
@@ -110,18 +114,19 @@
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public Set<String> getSupportedProperties() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File
Templates.
- }
-
public Cache getCache() {
// TODO : cache the cache reference?
+ if ( ! isOpen() ) {
+ throw new IllegalStateException("EntityManagerFactory is closed");
+ }
return new JPACache( sessionFactory );
}
public PersistenceUnitUtil getPersistenceUnitUtil() {
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ if ( ! isOpen() ) {
+ throw new IllegalStateException("EntityManagerFactory is closed");
+ }
+ return util;
}
public boolean isOpen() {
@@ -160,7 +165,7 @@
}
private static class HibernatePersistenceUnitUtil implements PersistenceUnitUtil,
Serializable {
- private final EntityManagerFactoryImpl emf;
+ private final HibernateEntityManagerFactory emf;
private HibernatePersistenceUnitUtil(EntityManagerFactoryImpl emf) {
this.emf = emf;
@@ -177,8 +182,6 @@
else {
return PersistenceUtilHelper.isLoadedWithReference( entity, attributeName ) !=
LoadState.NOT_LOADED;
}
-
-
}
public boolean isLoaded(Object entity) {
@@ -186,7 +189,13 @@
}
public Object getIdentifier(Object entity) {
- throw new UnsupportedOperationException( "Not yet implemented" );
+ final Class entityClass = Hibernate.getClass( entity );
+ final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata(
entityClass );
+ if (classMetadata == null) {
+ throw new IllegalArgumentException( entityClass + " is not an entity" );
+ }
+ //TODO does that work for @IdClass?
+ return classMetadata.getIdentifier( entity, EntityMode.POJO );
}
}
}
Show replies by date