jpa-2.0

How can I get all @Entity classes from a Persistence Unit?

試著忘記壹切 提交于 2019-12-03 10:44:27
Problem I'm writing a standalone utility program which, given a jar containing a JPA-2 annotated persistence unit, needs to programmatically get a list of all my @Entity classes in a particular persistence unit. I'd like to decide which of 2 approaches would be the way to go to get this information, and why; or if there is another better way I haven't thought of. Solution 1 Java program puts jar on the classpath, creates persistence unit from the classes in the jar using JavaSE methodologies. Then it uses the javax.persistence classes to get the JPA Metamodel, pull back list of class tokens

ElementCollection createAlias in hibernate API

旧城冷巷雨未停 提交于 2019-12-03 10:41:54
does anyone know if and how the solution for following question (which is written in the JPA API) can be written using the hibernate criteria API? To be more specific I have a Discussion entity that contains a list of participants (which is a list of usernames): @ElementCollection @Column(name = "user_name") @CollectionTable(name = "DISCUSSION_USER", joinColumns = @JoinColumn(name = "DISCUSSION_ID")) @OrderColumn(name = "ORDER_INDEX") private List<String> participants = new ArrayList<String>(); Now I need to retrieve all Discussions where a given username is a participant. If I would have

JPQL limit query [duplicate]

可紊 提交于 2019-12-03 10:34:18
问题 This question already has answers here : Limit number of results in JPQL (2 answers) Closed 3 years ago . How can I limit in a select query of JPQL named query? I need the limit to be done in the query level itself and not in the java layer!!! I am trying to use @NamedQueries(value = { @NamedQuery(name = UserNotification.QueryName.NOTIFICATION_DISPLAYED, query = "SELECT un FROM UserNotification un " + "WHERE un.orgId IN (:orgList) " + "AND un.user.id = :userId LIMIT 5") but in vain!!! Please

JPA 2.0 API maven artifact

依然范特西╮ 提交于 2019-12-03 10:33:44
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 Pascal Thivent 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 full javax:javaee-api:jar:6.0 artifact if you want something from Sun/Oracle... or just

JPA 2.0: count for arbitrary CriteriaQuery?

岁酱吖の 提交于 2019-12-03 09:28:21
问题 I am trying to implement the following convenience method: /** * Counts the number of results of a search. * @param criteria The criteria for the query. * @return The number of results of the query. */ public int findCountByCriteria(CriteriaQuery<?> criteria); In Hibernate, this is done by criteria.setProjection(Projections.rowCount()); What is the equivalent to the above in JPA? I found numerous simple count examples, but none of them made use of a CriteriaQuery whose row count should be

Properties reference for hibernate in persistence.xml

时光毁灭记忆、已成空白 提交于 2019-12-03 08:43:21
问题 Does anyone know a link, post, book or something else where are explained and nominalized all properties that you need and can use in persistence.xml file? 回答1: The JPA 2.0 supported properties ( javax.persistence.* ) can be found in JPA 2.0 specification. Vendor-specific properties can be found in appropriate vendor documentation: Hibernate properties (hibernate.*) EclipseLink properties (eclipselink.*) 回答2: Full list of properties, that hibernate uses, you can find in class org\hibernate

Why session bean method throw EjbTransactionRolledbackException when RuntimeException was thrown

僤鯓⒐⒋嵵緔 提交于 2019-12-03 08:20:18
I am trying to persist the entity with constraint validation, when invoke persist - there is constraint that thrown and the caller get EjbTransactionRolledbackException ... so I try to call the validation explicit and throw ConstraintViolationException / RuntimeException and still the caller get EjbTransactionRolledbackException ... when I throw MyException extends Exception - the caller get MyException Even when I call explicit sc.setRollBackOnly it's still happened :( This shouldn't be the behavior. what's going on? Configuration: Netbeans 6.9.1 Glassfish 3.0.1 JPA 2.0 (EclipseLink) EJB 3.1

JTA or LOCAL transactions in JPA2+Hibernate 3.6.0?

醉酒当歌 提交于 2019-12-03 07:41:00
We are in the process of re-thinking our tech stack and below are our choices (We can't live without Spring and Hibernate due to the complexity etc of the app). We are also moving from J2EE 1.4 to Java EE 5. Technology stack Java EE 5 JPA 2.0 (I know Java EE 5 only supports JPA 1.0 but we want to use Hibernate as the JPA provider) Hibernate 3.6.0 (We already have lots of hbm files with custom types etc. so we doesn't want to migrate them at this time to JPA. This means we want both jpa/hbm mappings work together and hence the Hibernate as the JPA provider instead of using the default that

Triggers vs. JPA @PrePersist for creation and update timestamps pros and cons

不问归期 提交于 2019-12-03 07:32:11
I am building a new web app and I am using Spring, JPA/Hibernate, and Postgres. Some of my tables have creation_ts and lastupdate_ts columns which are timestamp columns that track when an insert occurred and when the last update occurred on a row. I am also using a naming convention for columns in my tables so as a matter of design policy every table is guaranteed to have two columns pkey which is an integer surrogate key, and version for optimistic locking. I have two ways to keep these fields up to date. Option A: use triggers This is the solution I have in place right now, I have two

How to implement polymorphic JPA entities with generic relations

折月煮酒 提交于 2019-12-03 07:15:51
问题 I'm trying to use JPA 2.0 to create polymorphic entities with generic relations. There should be two tables, an event table and a notification table. Inside those table are concrete entities that are related to one another, like so: Event <---------- Notification<X extends Event> | | LoginEvent <------ LoginNotification extends Notification<LoginEvent> Logically this should be possible in hibernate, as it is possible in SQL: +----------+ +----------+ | Event | | Notif | +----------+ +--------