jpa-2.0

How to use persistence.xml and hibernate.cfg.xml in JUnit tests via eclipse?

自闭症网瘾萝莉.ら 提交于 2019-12-21 13:03:37
问题 I have been searching for an answer during quite a long time before coming here and ask this question. My problem is very simple : I cannot run any JUnit test when using the JPA Entity Manager API. It seems that my test is not reading the persistence.xml file. When I call new Configuration().configure().buildSessionFactory() , it works like a charm but an exception is thrown when calling Persistence.createEntityManagerFactory("myapp") is: javax.persistence.PersistenceException: No Persistence

Hibernate/Envers unable to read the mapped by attribute

左心房为你撑大大i 提交于 2019-12-21 09:29:34
问题 I am unable to implement many-to-many relation using join table (https://stackoverflow.com/a/7603036 & https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns). When I try to reproduce it persistence unit is unable to build EntityManagerFactory. It seems that Envers fails to read the mapped by attribute, although it looks good to me. What am I doing wrong? What is the right way™ to implement many-to-many relation with extra columns (and Envers)?

How to get entity manager or transaction in jpa listener

穿精又带淫゛_ 提交于 2019-12-21 09:13:21
问题 I was using Hibernate event listener like PostDeleteEventListener, PostInsertEventListener, PostUpdateEventListener to do some operations during insert, delete and update. Now I would like to use JPA listener to do this because if I like to move from Hibernate to any other JPA provider my listener should work. Hibernate listener gives me event from which I can get the transaction and check whether its committed or rollback. JPA listeners only provides me the entity object. Now how can I get

Better Exception Handling in JPA

落爺英雄遲暮 提交于 2019-12-21 07:24:11
问题 I used EJB3/JPA when persisting my entities and I am happy on how it is able to manage my DB related task. My only concern is on the exception handling. My sample code when saving entity always comes in this flavor. Most of the tutorials that I read on the net comes in this flavor also with no regards to exception handling. @Stateless public class StudentFacade{ @PersistenceContext(unitName = "MyDBPU") private EntityManager em; public void save(Student student) { em.persist(student); } } But

JPA 2: multiple column usage in foreign keys

回眸只為那壹抹淺笑 提交于 2019-12-21 07:11:36
问题 I am using Hibernate as persistence provider and modelling my entities with JPA 2. Now a question came up and i hope you can help me. In my application you can open up a Game, create groups of players in it and walk around on the map (tiles (2d)). First my entity definitions: Game: @Entity public class Game implements Serializable { @Id @SequenceGenerator(name = "gen_gameid", sequenceName = "seq_gameid") @GeneratedValue(generator="gen_gameid") private long gameid; /** * Playing Characters. */

java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext

别说谁变了你拦得住时间么 提交于 2019-12-21 07:08:07
问题 I am developing Spring MVC Hibernate Integration example. In this example I'm using Spring 4.1.9.RELEASE and Hibernate 5.1.0.Final . If I downgrade Hibernate version to 4.3.5.Final then it works. Now inorder to use hibernate 5 what else configuration do I need to change. Please refer more details below. Please find below the exception I see java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext at org.apache.catalina.loader.WebappClassLoaderBase.loadClass

Cross database joins in JPA

两盒软妹~` 提交于 2019-12-21 05:15:11
问题 Is it possible to do cross database table joins in JPA? I have a users table in one database which has a foreign key to a organizations table in a separate database. Both the databases are on same physical machine. Now MySQL allows me to write queries which span across multiple databases, but I am not sure how to do this with JPA. The @Entity annotations on the Java POJO's don't take the name of the database so there is no way to mark a cross DB relationship. Is there a workaround for this

CriteriaBuilder.and & CriteriaBuilder.or, how-to?

孤街浪徒 提交于 2019-12-21 03:37:41
问题 I'm trying to change the following HQL to use JPA Criteria: select distinct d from Department d left join fetch d.children c where d.parent is null and ( d.name like :term or c.name like :term ) order by d.name Department has a Set<Department> of children. Criteria: CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Department> c = cb.createQuery(Department.class); Root<Department> root = c.from(Department.class); root.fetch("children", JoinType.LEFT); Path<Department

JPA 2.0 API maven artifact

 ̄綄美尐妖づ 提交于 2019-12-21 03:12:50
问题 I am using JPA 2.0 and my persistence provider is Hibernate; however, I'd like to just include a standard API from javax, but in central, there is no 2.0 artifact. I am currently using the Hibernate JPA 2.0 artifact, but I'd like to use something more standard. Is this possible? Thanks, Walter 回答1: I am currently using the Hibernate JPA 2.0 artifact, but I'd like to use something more standard There is still no javax.persistence:persistence-api:jar:2.0 artifact from Sun/Oracle. Either use the

Is it possible to have immutable fields in Hibernate/JPA?

北慕城南 提交于 2019-12-20 17:32:49
问题 In our application, we need to have fields that are assignable only once. At first we thought of encapsulating the fields and making the setters private. However, some questions arouse: Without a public setter, is Hibernate still able to map the field from the database? Can I strip out the setter and make the field mutable only in the entity constructor? Finally, is there any standard JPA way to make a field immutable? Thanks in advance. 回答1: Ad. 1: I believe JPA uses plain private fields for