jpa-2.0

JPA/Hibernate Static Metamodel Attributes not Populated — NullPointerException

不问归期 提交于 2019-11-26 09:02:33
问题 I would like to use JPA2 Criteria API with metamodel objects, which seems to be pretty easy: ... Root<JPAAlbum> albm = cq.from(JPAAlbum.class); ... albm.get(JPAAlbum_.theme) ... ; but this Root.get always throws a NullPointerException . JPAAlbum_.theme was automatically generated by Hibernate and looks like public static volatile SingularAttribute<JPAAlbum, JPATheme> theme; but it\'s obviously never populated. Am I missing a step in the initialization of the framework ? EDIT: here is a

JPA CriteriaBuilder - How to use “IN” comparison operator

折月煮酒 提交于 2019-11-26 09:00:08
问题 Can you please help me how to convert the following codes to using \"in\" operator of criteria builder? I need to filter by using list/array of usernames using \"in\". I also tried to search using JPA CriteriaBuilder - \"in\" method but cannot find good result. So I would really appreciate also if you can give me reference URLs for this topic. Thanks. Here is my codes: //usersList is a list of User that I need to put inside IN operator CriteriaBuilder builder = getJpaTemplate()

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

谁说胖子不能爱 提交于 2019-11-26 08:21:46
问题 when i try to using bean validation with JPA using hibernate , the follwoing exception will occur : Exception in thread \"main\" javax.persistence.PersistenceException: [PersistenceUnit: Chapter11] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory

Generate JPA 2 Entities from existing Database

纵饮孤独 提交于 2019-11-26 08:06:13
问题 How can I generate JPA2 compliant @Entity from existing Databases?. I found this: Question Still its not clear if JBoss will generate compliant JPA2 and also I would like to know if there is a vendor independent way to do this. 回答1: You can use a plugin like Eclipse Dali to do the trick for you. You can refer to the documentation, section 3.11 Generating Entities from Tables. I do not know of any specific vendor independent tool to do this, though. 回答2: Try using OPENJPA Reverse mapping tools

java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities

眉间皱痕 提交于 2019-11-26 07:41:07
问题 I have 3 entities with ManyToMany relationships: Role Entity: @Entity public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer roleID; private String roleName; private String description; @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER) @JoinTable(name = \"role_permission\", joinColumns = {@JoinColumn(name = \"role_id\")}, inverseJoinColumns = {@JoinColumn(name = \"permission_id\")}) private Set

JPA 2.0 many-to-many with extra column

寵の児 提交于 2019-11-26 06:37:15
问题 I\'m trying to do a ManyToMany relationship in JPA 2.0 (JBoss 7.1.1) with an extra column (in bold, below) in the relationship, like: Employer EmployerDeliveryAgent DeliveryAgent (id,...) (employer_id, deliveryAgent_id, **ref**) (id,...) I wouldn\'t like to have duplicate attributes, so I would like to apply the second solution presented in http://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/ . But I can\'t get it to work, I get several

@OrderColumn annotation in Hibernate 3.5

此生再无相见时 提交于 2019-11-26 06:33:58
问题 I\'m trying to use the @OrderColumn annotation with Hibernate 3.5 @OneToMany(mappedBy = \"parent\",fetch=FetchType.EAGER, cascade=CascadeType.ALL) @OrderColumn(name = \"pos\") private List<Children> childrenCollection; When retrieving data, everything works fine. But I can\'t make it reorder elements in the List and save the new order to the database. 回答1: The combination of @OneToMany(mappedBy="...") and @OrderColumn is not supported by Hibernate. This JIRA issue tracks a request to throw a

JPA: unidirectional many-to-one and cascading delete

你说的曾经没有我的故事 提交于 2019-11-26 05:17:05
问题 Say I have a unidirectional @ManyToOne relationship like the following: @Entity public class Parent implements Serializable { @Id @GeneratedValue private long id; } @Entity public class Child implements Serializable { @Id @GeneratedValue private long id; @ManyToOne @JoinColumn private Parent parent; } If I have a parent P and children C 1 ...C n referencing back to P, is there a clean and pretty way in JPA to automatically remove the children C 1 ...C n when P is removed (i.e. entityManager

How to properly express JPQL “join fetch” with “where” clause as JPA 2 CriteriaQuery?

独自空忆成欢 提交于 2019-11-26 04:39:46
问题 Consider the following JPQL query: SELECT foo FROM Foo foo INNER JOIN FETCH foo.bar bar WHERE bar.baz = :baz I\'m trying to translate this into a Critieria query. This is as far as I have gotten: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Foo> cq = cb.createQuery(Foo.class); Root<Foo> r = cq.from(Foo.class); Fetch<Foo, Bar> fetch = r.fetch(Foo_.bar, JoinType.INNER); Join<Foo, Bar> join = r.join(Foo_.bar, JoinType.INNER); cq.where(cb.equal(join.get(Bar_.baz), value); The

Hibernate - @ElementCollection - Strange delete/insert behavior

微笑、不失礼 提交于 2019-11-26 04:21:51
问题 @Entity public class Person { @ElementCollection @CollectionTable(name = \"PERSON_LOCATIONS\", joinColumns = @JoinColumn(name = \"PERSON_ID\")) private List<Location> locations; [...] } @Embeddable public class Location { [...] } Given the following class structure, when I try to add a new location to the list of Person\'s Locations, it always results in the following SQL queries: DELETE FROM PERSON_LOCATIONS WHERE PERSON_ID = :idOfPerson And A lotsa\' inserts into the PERSON_LOCATIONS table