Author: epbernard
Date: 2009-05-07 17:34:21 -0400 (Thu, 07 May 2009)
New Revision: 16523
Modified:
core/trunk/annotations/pom.xml
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/generics/Classes.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java
core/trunk/cache-jbosscache2/pom.xml
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/PackagedEntityManagerTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
core/trunk/envers/pom.xml
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
core/trunk/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java
Log:
HHH-3906 EJB-436 ANN-830 Move to JPA 2 API as a dependency
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2009-05-07 20:33:16 UTC (rev 16522)
+++ core/trunk/annotations/pom.xml 2009-05-07 21:34:21 UTC (rev 16523)
@@ -58,8 +58,8 @@
<artifactId>hibernate-commons-annotations</artifactId>
</dependency>
<dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
</dependency>
<dependency>
<groupId>javassist</groupId>
@@ -96,9 +96,9 @@
<version>${version}</version>
</dependency>
<dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
- <version>1.0</version>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
+ <version>2.0.Beta1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -70,6 +70,7 @@
import javax.persistence.TableGenerator;
import javax.persistence.Transient;
import javax.persistence.Version;
+import javax.persistence.ElementCollection;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -1238,7 +1239,9 @@
}
else if ( joinColumns == null &&
( property.isAnnotationPresent( OneToMany.class )
- || property.isAnnotationPresent( CollectionOfElements.class ) ) ) {
+ || property.isAnnotationPresent( CollectionOfElements.class ) //legacy Hibernate
+ || property.isAnnotationPresent( ElementCollection.class )
+ ) ) {
OneToMany oneToMany = property.getAnnotation( OneToMany.class );
String mappedBy = oneToMany != null ?
oneToMany.mappedBy() :
@@ -1454,11 +1457,13 @@
}
else if ( property.isAnnotationPresent( OneToMany.class )
|| property.isAnnotationPresent( ManyToMany.class )
- || property.isAnnotationPresent( CollectionOfElements.class )
+ || property.isAnnotationPresent( CollectionOfElements.class ) //legacy Hibernate
+ || property.isAnnotationPresent( ElementCollection.class )
|| property.isAnnotationPresent( ManyToAny.class ) ) {
OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
- CollectionOfElements collectionOfElementsAnn = property.getAnnotation(
CollectionOfElements.class );
+ ElementCollection elementCollectionAnn = property.getAnnotation(
ElementCollection.class );
+ CollectionOfElements collectionOfElementsAnn = property.getAnnotation(
CollectionOfElements.class ); //legacy hibernate
org.hibernate.annotations.IndexColumn indexAnn = property.getAnnotation(
org.hibernate.annotations.IndexColumn.class
);
@@ -1585,7 +1590,9 @@
collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(),
hibernateCascade ) );
collectionBinder.setOneToMany( true );
}
- else if ( collectionOfElementsAnn != null ) {
+ else if ( elementCollectionAnn != null
+ || collectionOfElementsAnn != null //Hibernate legacy
+ ) {
for (Ejb3JoinColumn column : joinColumns) {
if ( column.isSecondary() ) {
throw new NotYetImplementedException( "Collections having FK in secondary
table" );
@@ -1593,8 +1600,11 @@
}
collectionBinder.setFkJoinColumns( joinColumns );
mappedBy = "";
+ final Class<?> targetElement = elementCollectionAnn != null ?
+ elementCollectionAnn.targetClass() :
+ collectionOfElementsAnn.targetElement();
collectionBinder.setTargetEntity(
- mappings.getReflectionManager().toXClass( collectionOfElementsAnn.targetElement()
)
+ mappings.getReflectionManager().toXClass( targetElement )
);
//collectionBinder.setCascadeStrategy( getCascadeStrategy(
embeddedCollectionAnn.cascade(), hibernateCascade ) );
collectionBinder.setOneToMany( true );
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -38,6 +38,7 @@
import javax.persistence.ManyToMany;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
+import javax.persistence.ElementCollection;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -449,7 +450,9 @@
tableBinder, mappings
);
if ( collectionType.isAnnotationPresent( Embeddable.class )
- || property.isAnnotationPresent( CollectionOfElements.class ) ) {
+ || property.isAnnotationPresent( CollectionOfElements.class ) //legacy hibernate
+ || property.isAnnotationPresent( ElementCollection.class ) //JPA 2
+ ) {
// do it right away, otherwise @ManyToon on composite element call addSecondPass
// and raise a ConcurrentModificationException
//sp.doSecondPass( CollectionHelper.EMPTY_MAP );
@@ -483,7 +486,8 @@
Fetch fetch = property.getAnnotation( Fetch.class );
OneToMany oneToMany = property.getAnnotation( OneToMany.class );
ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
- CollectionOfElements elements = property.getAnnotation( CollectionOfElements.class );
+ CollectionOfElements collectionOfElements = property.getAnnotation(
CollectionOfElements.class ); //legacy hibernate
+ ElementCollection elementCollection = property.getAnnotation( ElementCollection.class
); //jpa 2
ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
FetchType fetchType;
if ( oneToMany != null ) {
@@ -492,9 +496,12 @@
else if ( manyToMany != null ) {
fetchType = manyToMany.fetch();
}
- else if ( elements != null ) {
- fetchType = elements.fetch();
+ else if ( elementCollection != null ) {
+ fetchType = elementCollection.fetch();
}
+ else if ( collectionOfElements != null ) {
+ fetchType = collectionOfElements.fetch();
+ }
else if ( manyToAny != null ) {
fetchType = FetchType.LAZY;
}
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -102,6 +102,7 @@
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
+import javax.persistence.ElementCollection;
import org.dom4j.Attribute;
import org.dom4j.Element;
@@ -563,7 +564,8 @@
defaultToJoinTable = defaultToJoinTable &&
( ( annotationClass == ManyToMany.class && StringHelper.isEmpty( (
(ManyToMany) annotation ).mappedBy() ) )
|| ( annotationClass == OneToMany.class && StringHelper.isEmpty( (
(OneToMany) annotation ).mappedBy() ) )
- || ( annotationClass == CollectionOfElements.class )
+ || ( annotationClass == CollectionOfElements.class ) //legacy Hibernate
+ || ( annotationClass == ElementCollection.class )
);
final Class<JoinTable> annotationType = JoinTable.class;
if ( defaultToJoinTable
@@ -699,7 +701,41 @@
annotation = getJavaAnnotation( Columns.class );
addIfNotNull( annotationList, annotation );
}
- else if ( isJavaAnnotationPresent( CollectionOfElements.class ) ) {
+ else if ( isJavaAnnotationPresent( ElementCollection.class ) ) { //JPA2
+ annotation = overridesDefaultsInJoinTable( getJavaAnnotation( ElementCollection.class
), defaults );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( JoinColumn.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( JoinColumns.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( PrimaryKeyJoinColumn.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( PrimaryKeyJoinColumns.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( MapKey.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( OrderBy.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( AttributeOverride.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( AttributeOverrides.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( AssociationOverride.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( AssociationOverrides.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( Lob.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( Enumerated.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( Temporal.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( Column.class );
+ addIfNotNull( annotationList, annotation );
+ annotation = getJavaAnnotation( Columns.class );
+ addIfNotNull( annotationList, annotation );
+ }
+ else if ( isJavaAnnotationPresent( CollectionOfElements.class ) ) { //legacy
Hibernate
annotation = overridesDefaultsInJoinTable( getJavaAnnotation(
CollectionOfElements.class ), defaults );
addIfNotNull( annotationList, annotation );
annotation = getJavaAnnotation( JoinColumn.class );
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/array/Contest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -7,6 +7,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
+import javax.persistence.ElementCollection;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@@ -40,7 +41,7 @@
this.results = results;
}
- @CollectionOfElements
+ @ElementCollection
@IndexColumn(name = "pos", base=1)
public Month[] getHeldIn() {
return heldIn;
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Screen.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -8,6 +8,7 @@
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.CascadeType;
+import javax.persistence.ElementCollection;
import javax.validation.constraints.NotNull;
import javax.validation.Valid;
@@ -54,7 +55,8 @@
this.powerSupply = powerSupply;
}
- @CollectionOfElements @Valid
+ @ElementCollection
+ @Valid
public Set<DisplayConnector> getConnectors() {
return connectors;
}
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -16,6 +16,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
+import javax.persistence.ElementCollection;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@@ -66,7 +67,7 @@
this.lastName = lastName;
}
- @CollectionOfElements
+ @CollectionOfElements //keep hibernate legacy for test purposes
public Set<String> getNickNames() {
return nickNames;
}
@@ -75,7 +76,7 @@
this.nickNames = nickName;
}
- @CollectionOfElements
+ @ElementCollection
@JoinTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name =
"BoyId"))
@Column(name = "score", nullable = false)
public Map<String, Integer> getScorePerNickName() {
@@ -86,7 +87,7 @@
this.scorePerNickName = scorePerNickName;
}
- @CollectionOfElements
+ @ElementCollection
@JoinTable(
name = "BoyFavoriteNumbers",
joinColumns = @JoinColumn(name = "BoyId")
@@ -101,7 +102,7 @@
this.favoriteNumbers = favoriteNumbers;
}
- @CollectionOfElements
+ @CollectionOfElements //TODO migration to ElementCollection
"element.serial"??
@AttributeOverride(name = "element.serial", column = @Column(name =
"serial_nbr"))
public Set<Toy> getFavoriteToys() {
return favoriteToys;
@@ -111,7 +112,7 @@
this.favoriteToys = favoriteToys;
}
- @CollectionOfElements
+ @ElementCollection
@Enumerated(EnumType.STRING)
public Set<Character> getCharacters() {
return characters;
@@ -121,7 +122,7 @@
this.characters = characters;
}
- @CollectionOfElements(fetch = FetchType.EAGER)
+ @ElementCollection(fetch = FetchType.EAGER)
//@Where(clause = "b_likes=false")
public Set<CountryAttitude> getCountryAttitudes() {
return countryAttitudes;
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -1,18 +1,18 @@
//$Id$
package org.hibernate.test.annotations.collectionelement;
+import java.io.Serializable;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
-import java.util.Locale;
-import java.io.Serializable;
import javax.persistence.Column;
+import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
-import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Fetch;
-import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.MapKey;
/**
* @author Emmanuel Bernard
@@ -32,7 +32,7 @@
private Map<String, String> variations =
new HashMap<String, String>( 1 );
- @CollectionOfElements
+ @ElementCollection
@MapKey( columns = @Column( name = "language_code" ) )
@Fetch( FetchMode.JOIN )
@Filter( name = "selectedLocale",
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -4,12 +4,11 @@
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-
+import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
@@ -25,7 +24,7 @@
private Integer id;
@MapKey(type = @Type(type="integer") )
- @CollectionOfElements
+ @ElementCollection
@Sort(type = SortType.NATURAL)
@Type(type = "float")
private SortedMap<Integer, Float> values = new TreeMap<Integer, Float>();
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/A.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -6,6 +6,7 @@
*/
import java.util.List;
+import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@@ -13,7 +14,6 @@
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@Entity
@@ -23,7 +23,7 @@
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "aSequence"
)
@SequenceGenerator( name = "aSequence", sequenceName = "seq_A" )
private int id;
- @CollectionOfElements
+ @ElementCollection
@IndexColumn( name = "ndx" )
private List<B> listOfB;
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/B.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -3,10 +3,8 @@
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
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -23,7 +23,7 @@
public class Sale {
@Id @GeneratedValue private Integer id;
- @CollectionOfElements
+ @CollectionOfElements //TODO migrate to @ElementCollection, what about @CollectionId
@JoinTable(
name = "contact",
joinColumns = @JoinColumn(name = "n_key_person"))
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/generics/Classes.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/generics/Classes.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/generics/Classes.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -6,9 +6,10 @@
* @author Edward Costello
* @author Paolo Perrotta
*/
+
import java.util.HashSet;
import java.util.Set;
-
+import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.Entity;
@@ -16,8 +17,6 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
-import org.hibernate.annotations.CollectionOfElements;
-
public class Classes {
@Embeddable
@@ -41,7 +40,7 @@
@GeneratedValue(strategy=GenerationType.AUTO)
Long id;
- @CollectionOfElements
+ @ElementCollection
Set<Edition<String>> editions = new
HashSet<Edition<String>>();
}
}
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -34,7 +34,7 @@
@JoinTable(name = "Gas_per_key")
public Map<GasKey, Gas> gasesPerKey = new HashMap<GasKey, Gas>();
- @CollectionOfElements
+ @CollectionOfElements //TODO migrate to @ElementCollection ; @MapKeyManyToMany ??
@Column(name="composition_rate")
@MapKeyManyToMany(joinColumns = @JoinColumn(name="gas_id"))
@JoinTable(name = "Composition", joinColumns = @JoinColumn(name =
"atmosphere_id"))
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -1,15 +1,15 @@
//$Id$
package org.hibernate.test.annotations.target;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
+import javax.persistence.ElementCollection;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.MapKey;
-import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.MapKeyManyToMany;
/**
@@ -25,7 +25,7 @@
@MapKey(targetElement = SizeImpl.class)
private Map<Size, Luggage> luggagesBySize = new HashMap<Size, Luggage>();
- @CollectionOfElements(targetElement = SizeImpl.class)
+ @ElementCollection(targetClass = SizeImpl.class)
@MapKeyManyToMany(targetEntity = LuggageImpl.class)
private Map<Luggage, Size> sizePerLuggage = new HashMap<Luggage, Size>();
Modified: core/trunk/cache-jbosscache2/pom.xml
===================================================================
--- core/trunk/cache-jbosscache2/pom.xml 2009-05-07 20:33:16 UTC (rev 16522)
+++ core/trunk/cache-jbosscache2/pom.xml 2009-05-07 21:34:21 UTC (rev 16523)
@@ -56,10 +56,9 @@
</dependency>
<dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
- <version>1.0</version>
- <scope>test</scope>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
+ <version>2.0.Beta1</version>
</dependency>
</dependencies>
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, the OpenSource EJB server Distributable under LGPL license. See terms of
license at
*
gnu.org.
@@ -10,6 +10,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Map;
+import java.util.Set;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction;
@@ -22,6 +23,10 @@
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.metamodel.Metamodel;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.QueryBuilder;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.transaction.Status;
import javax.transaction.Synchronization;
@@ -98,6 +103,10 @@
}
}
+ public Query createQuery(CriteriaQuery criteriaQuery) {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public Query createNamedQuery(String name) {
//adjustFlushMode();
org.hibernate.Query namedQuery;
@@ -204,6 +213,21 @@
}
}
+ public <T> T find(Class<T> tClass, Object o, Map<String, Object>
stringObjectMap) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public <T> T find(Class<T> tClass, Object o, LockModeType lockModeType) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public <T> T find(Class<T> tClass, Object o, LockModeType lockModeType,
Map<String, Object> stringObjectMap) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
private void checkTransactionNeeded() {
if ( persistenceContextType == PersistenceContextType.TRANSACTION && !
isTransactionInProgress() ) {
//no need to mark as rollback, no tx in progress
@@ -277,6 +301,21 @@
}
}
+ public void refresh(Object o, Map<String, Object> stringObjectMap) {
+ //FIXME
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void refresh(Object o, LockModeType lockModeType) {
+ //FIXME
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void refresh(Object o, LockModeType lockModeType, Map<String, Object>
stringObjectMap) {
+ //FIXME
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
public boolean contains(Object entity) {
try {
if ( entity != null
@@ -295,6 +334,26 @@
}
}
+ public LockModeType getLockMode(Object o) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public void setProperty(String s, Object o) {
+ //FIXME
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Map<String, Object> getProperties() {
+ //FIXME
+ 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 void flush() {
try {
if ( ! isTransactionInProgress() ) {
@@ -326,6 +385,21 @@
return tx;
}
+ public EntityManagerFactory getEntityManagerFactory() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public QueryBuilder getQueryBuilder() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Metamodel getMetamodel() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public void setFlushMode(FlushModeType flushModeType) {
this.flushModeType = flushModeType;
if ( flushModeType == FlushModeType.AUTO ) {
@@ -349,6 +423,10 @@
}
}
+ public void detach(Object entity) {
+ getSession().evict( entity );
+ }
+
public FlushModeType getFlushMode() {
FlushMode mode = getSession().getFlushMode();
if ( mode == FlushMode.AUTO ) {
@@ -387,6 +465,11 @@
}
}
+ public void lock(Object o, LockModeType lockModeType, Map<String, Object>
stringObjectMap) {
+ //FIXME
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
private LockMode getLockMode(LockModeType lockMode) {
switch ( lockMode ) {
case READ:
@@ -431,6 +514,13 @@
joinTransaction( false );
}
+ public <T> T unwrap(Class<T> clazz) {
+ if (clazz.equals( Session.class ) ) return (T) getSession();
+ if (clazz.equals( SessionImplementor.class ) ) return (T) getSession();
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
private void joinTransaction(boolean ignoreNotJoining) {
//set the joined status
getSession().isOpen(); //for sync
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -2,8 +2,12 @@
package org.hibernate.ejb;
import java.util.Map;
+import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContextType;
+import javax.persistence.Cache;
+import javax.persistence.metamodel.Metamodel;
+import javax.persistence.criteria.QueryBuilder;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.SessionFactory;
@@ -42,10 +46,35 @@
);
}
+ public QueryBuilder getQueryBuilder() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Metamodel getMetamodel() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public void close() {
sessionFactory.close();
}
+ public Map<String, Object> getProperties() {
+ //FIXME
+ 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() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public boolean isOpen() {
return ! sessionFactory.isClosed();
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -2,9 +2,24 @@
package org.hibernate.ejb;
import java.util.Map;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceException;
import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.LoadState;
+import org.hibernate.Hibernate;
+import org.hibernate.intercept.FieldInterceptionHelper;
+import org.hibernate.intercept.FieldInterceptor;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.LazyInitializer;
+
/**
* Hibernate EJB3 persistence provider implementation
*
@@ -132,7 +147,136 @@
return configured != null ? configured.buildEntityManagerFactory() : null;
}
+ public LoadState isLoadedWithoutReference(Object proxy, String property) {
+ Object entity;
+ boolean sureFromUs = false;
+ if ( proxy instanceof HibernateProxy ) {
+ LazyInitializer li = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer();
+ if ( li.isUninitialized() ) {
+ return LoadState.NOT_LOADED;
+ }
+ else {
+ entity = li.getImplementation();
+ }
+ sureFromUs = true;
+ }
+ else {
+ entity = proxy;
+ }
+
+ //we are instrumenting but we can't assume we are the only ones
+ if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
+ FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity
);
+ final boolean isInitialized = interceptor == null || interceptor.isInitialized(
property );
+ LoadState state;
+ if (isInitialized && interceptor != null) {
+ state = LoadState.LOADED;
+ }
+ else if ( interceptor != null && (! isInitialized)) {
+ state = LoadState.NOT_LOADED;
+ }
+ else if ( sureFromUs ) { //interceptor == null
+ state = LoadState.LOADED;
+ }
+ else {
+ state = LoadState.UNKNOWN;
+ }
+
+ return state;
+ }
+ else {
+ //can't do sureFromUs ? LoadState.LOADED : LoadState.UNKNOWN;
+ //is that an association?
+ return LoadState.UNKNOWN;
+ }
+ }
+
+ public LoadState isLoadedWithReference(Object proxy, String property) {
+ //for sure we don't instrument and for sure it's not a lazy proxy
+ Object object = get(proxy, property);
+ return isLoaded( object );
+ }
+
+ private Object get(Object proxy, String property) {
+ final Class<?> clazz = proxy.getClass();
+ try {
+ try {
+ final Field field = clazz.getField( property );
+ setAccessibility( field );
+ return field.get( proxy );
+ }
+ catch ( NoSuchFieldException e ) {
+ final Method method = getMethod( clazz, property );
+ if (method != null) {
+ setAccessibility( method );
+ return method.invoke( proxy );
+ }
+ else {
+ throw new PersistenceException( "Unable to find field or method: "
+ + clazz + "#"
+ + property);
+ }
+ }
+ }
+ catch ( IllegalAccessException e ) {
+ throw new PersistenceException( "Unable to access field or method: "
+ + clazz + "#"
+ + property, e);
+ }
+ catch ( InvocationTargetException e ) {
+ throw new PersistenceException( "Unable to access field or method: "
+ + clazz + "#"
+ + property, e);
+ }
+ }
+
/**
+ * Returns the method with the specified name or <code>null</code> if it
does not exist.
+ *
+ * @param clazz The class to check.
+ * @param methodName The method name.
+ *
+ * @return Returns the method with the specified name or <code>null</code>
if it does not exist.
+ */
+ public static Method getMethod(Class<?> clazz, String methodName) {
+ try {
+ char string[] = methodName.toCharArray();
+ string[0] = Character.toUpperCase( string[0] );
+ methodName = new String( string );
+ try {
+ return clazz.getMethod( "get" + methodName );
+ }
+ catch ( NoSuchMethodException e ) {
+ return clazz.getMethod( "is" + methodName );
+ }
+ }
+ catch ( NoSuchMethodException e ) {
+ return null;
+ }
+ }
+
+ public static void setAccessibility(Member member) {
+ if ( !Modifier.isPublic( member.getModifiers() ) ) {
+ //Sun's ease of use, sigh...
+ ( ( AccessibleObject ) member ).setAccessible( true );
+ }
+ }
+
+ public LoadState isLoaded(Object o) {
+ if ( o instanceof HibernateProxy ) {
+ final boolean isInitialized = !( ( HibernateProxy ) o
).getHibernateLazyInitializer().isUninitialized();
+ return isInitialized ? LoadState.LOADED : LoadState.NOT_LOADED;
+ }
+ else if ( o instanceof PersistentCollection ) {
+ final boolean isInitialized = ( ( PersistentCollection ) o ).wasInitialized();
+ return isInitialized ? LoadState.LOADED : LoadState.NOT_LOADED;
+ }
+ else {
+ return LoadState.UNKNOWN;
+ }
+ }
+
+ /**
* create a factory from a canonical version
* @deprecated
*/
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2009-05-07
20:33:16 UTC (rev 16522)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -7,6 +7,7 @@
import java.util.List;
import java.util.HashSet;
import java.util.Set;
+import java.util.Map;
import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
@@ -14,6 +15,7 @@
import javax.persistence.TemporalType;
import static javax.persistence.TemporalType.*;
import javax.persistence.TransactionRequiredException;
+import javax.persistence.LockModeType;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
@@ -32,6 +34,7 @@
private HibernateEntityManagerImplementor em;
private Boolean isPositional = null;
private int maxResults = -1;
+ private int firstResult;
public QueryImpl(org.hibernate.Query query, AbstractEntityManagerImpl em) {
this.query = query;
@@ -143,6 +146,10 @@
return this;
}
+ public int getMaxResults() {
+ return maxResults == -1 ? Integer.MAX_VALUE : maxResults; //stupid spec MAX_VALUE??
+ }
+
public Query setFirstResult(int firstResult) {
if ( firstResult < 0 ) {
throw new IllegalArgumentException(
@@ -152,9 +159,14 @@
);
}
query.setFirstResult( firstResult );
+ this.firstResult = firstResult;
return this;
}
+ public int getFirstResult() {
+ return firstResult;
+ }
+
public Query setHint(String hintName, Object value) {
try {
if ( "org.hibernate.timeout".equals( hintName ) ) {
@@ -192,6 +204,16 @@
return this;
}
+ public Map<String, Object> getHints() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Set<String> getSupportedHints() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public Query setParameter(String name, Object value) {
try {
if ( value instanceof Collection ) {
@@ -351,6 +373,16 @@
}
}
+ public Map<String, Object> getNamedParameters() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public List getPositionalParameters() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public Query setFlushMode(FlushModeType flushMode) {
if ( flushMode == FlushModeType.AUTO ) {
query.setFlushMode( FlushMode.AUTO );
@@ -360,4 +392,24 @@
}
return this;
}
+
+ public FlushModeType getFlushMode() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Query setLockMode(LockModeType lockModeType) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public LockModeType getLockMode() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public <T> T unwrap(Class<T> tClass) {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
}
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/PackagedEntityManagerTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -219,7 +219,7 @@
public void testListeners() throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"manager1", new HashMap() );
EntityManager em = emf.createEntityManager();
- EventListeners eventListeners = ( (SessionImplementor) em.getDelegate()
).getListeners();
+ EventListeners eventListeners = em.unwrap(SessionImplementor.class).getListeners();
assertEquals(
"Explicit pre-insert event through hibernate.ejb.event.pre-insert does not
work",
eventListeners.getPreInsertEventListeners().length,
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -8,6 +8,8 @@
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.persistence.Caching;
+import javax.persistence.ValidationMode;
import javax.sql.DataSource;
import org.hibernate.cfg.Environment;
@@ -71,6 +73,10 @@
return properties;
}
+ public String PersistenceXMLSchemaVersion() {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@@ -87,6 +93,16 @@
return true;
}
+ public Caching getCaching() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public ValidationMode getValidationMode() {
+ //FIXME
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public void addTransformer(ClassTransformer transformer) {
}
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -72,7 +72,7 @@
c2.setB2( anotherB2 );
}
}
- Statistics statistics = ( (Session) em.getDelegate()
).getSessionFactory().getStatistics();
+ Statistics statistics = em.unwrap(Session.class).getSessionFactory().getStatistics();
statistics.setStatisticsEnabled( true );
statistics.clear();
em.persist( c2 );
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -271,7 +271,7 @@
em.flush();
em.clear();
book.setName( "kitty kid2"); //non updated version
- ( (Session) em.getDelegate() ).update( book );
+ em.unwrap( Session.class ).update( book );
try {
em.getTransaction().commit();
fail( "Commit should be rollbacked" );
Modified: core/trunk/envers/pom.xml
===================================================================
--- core/trunk/envers/pom.xml 2009-05-07 20:33:16 UTC (rev 16522)
+++ core/trunk/envers/pom.xml 2009-05-07 21:34:21 UTC (rev 16523)
@@ -70,8 +70,9 @@
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
+ <version>2.0.Beta1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReaderFactory.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -24,14 +24,14 @@
package org.hibernate.envers;
import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.event.AuditEventListener;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.reader.AuditReaderImpl;
import static org.hibernate.envers.tools.ArraysTools.arrayIncludesInstanceOf;
-
-import org.hibernate.Session;
-import org.hibernate.engine.SessionImplementor;
import org.hibernate.event.EventListeners;
import org.hibernate.event.PostInsertEventListener;
@@ -81,17 +81,11 @@
* listeners aren't installed.
*/
public static AuditReader get(EntityManager entityManager) throws AuditException {
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
-
- if (entityManager.getDelegate() instanceof EntityManager) {
- entityManager = (EntityManager) entityManager.getDelegate();
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
- }
-
- throw new AuditException("Hibernate EntityManager not present!");
+ try {
+ return get( entityManager.unwrap(Session.class) );
+ }
+ catch ( PersistenceException e ) {
+ throw new AuditException("Hibernate EntityManager not present!");
+ }
}
}
Modified: core/trunk/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java
===================================================================
--- core/trunk/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java 2009-05-07
20:33:16 UTC (rev 16522)
+++ core/trunk/envers/src/main/java/org/jboss/envers/VersionsReaderFactory.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -25,6 +25,7 @@
package org.jboss.envers;
import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
import org.hibernate.envers.event.AuditEventListener;
import org.hibernate.envers.reader.AuditReaderImpl;
@@ -81,16 +82,11 @@
* listeners aren't installed.
*/
public static VersionsReader get(EntityManager entityManager) throws
VersionsException {
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
-
- if (entityManager.getDelegate() instanceof EntityManager) {
- if (entityManager.getDelegate() instanceof Session) {
- return get((Session) entityManager.getDelegate());
- }
- }
-
- throw new VersionsException("Hibernate EntityManager not present!");
+ try {
+ return get( entityManager.unwrap(Session.class) );
+ }
+ catch ( PersistenceException e ) {
+ throw new VersionsException("Hibernate EntityManager not present!");
+ }
}
}
\ No newline at end of file
Modified:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/flush/AbstractFlushTest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -25,6 +25,7 @@
import java.io.IOException;
import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.entities.StrTestEntity;
@@ -45,18 +46,12 @@
}
private static Session getSession(EntityManager em) {
- Object delegate = em.getDelegate();
- if (delegate instanceof Session) {
- return (Session) delegate;
- } else if (delegate instanceof EntityManager) {
- Object delegate2 = ((EntityManager) delegate).getDelegate();
-
- if (delegate2 instanceof Session) {
- return (Session) delegate2;
- }
- }
-
- throw new RuntimeException("Invalid entity manager");
+ try {
+ return em.unwrap( Session.class );
+ }
+ catch ( PersistenceException e ) {
+ throw new RuntimeException("Invalid entity manager", e);
+ }
}
@BeforeClass(dependsOnMethods = "init")
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java 2009-05-07
20:33:16 UTC (rev 16522)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/various/HsqlTest.java 2009-05-07
21:34:21 UTC (rev 16523)
@@ -100,7 +100,7 @@
entityManager.getTransaction().begin();
- Session sesion = (Session) entityManager.getDelegate();
+ Session sesion = entityManager.unwrap(Session.class);
System.out.println(sesion.createQuery(
"select e from org.hibernate.envers.demo.Person_versions e " +
"where " +