Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-11426 - NullPointerException in getPersistenceUnitUtil().getIdent…
…ifier() on detached enhanced entity
- Loading branch information
Showing
3 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../java/org/hibernate/test/bytecode/enhancement/detached/DetachedGetIdentifierTestTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
package org.hibernate.test.bytecode.enhancement.detached; | |||
|
|||
import org.hibernate.cfg.Configuration; | |||
import org.hibernate.cfg.Environment; | |||
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask; | |||
import org.junit.Assert; | |||
|
|||
import javax.persistence.Entity; | |||
import javax.persistence.EntityManager; | |||
import javax.persistence.GeneratedValue; | |||
import javax.persistence.Id; | |||
|
|||
/** | |||
* @author Luis Barreiro | |||
*/ | |||
public class DetachedGetIdentifierTestTask extends AbstractEnhancerTestTask { | |||
|
|||
public Class<?>[] getAnnotatedClasses() { | |||
return new Class<?>[]{SimpleEntity.class}; | |||
} | |||
|
|||
public void prepare() { | |||
Configuration cfg = new Configuration(); | |||
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); | |||
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" ); | |||
super.prepare( cfg ); | |||
} | |||
|
|||
public void execute() { | |||
EntityManager em = getFactory().createEntityManager(); | |||
em.getTransaction().begin(); | |||
|
|||
SimpleEntity se = new SimpleEntity(); | |||
se.name = "test"; | |||
se = em.merge( se ); | |||
|
|||
Assert.assertNotNull( getFactory().getPersistenceUnitUtil().getIdentifier( se ) ); | |||
|
|||
em.getTransaction().commit(); | |||
em.close(); | |||
|
|||
// Call as detached entity | |||
Assert.assertNotNull( getFactory().getPersistenceUnitUtil().getIdentifier( se ) ); | |||
} | |||
|
|||
protected void cleanup() { | |||
} | |||
|
|||
@Entity | |||
public static class SimpleEntity { | |||
|
|||
@Id | |||
@GeneratedValue | |||
private Long id; | |||
|
|||
private String name; | |||
|
|||
} | |||
} |