jpa-2.0

Getting “with clause can only reference columns in the driving table” when trying to write a JPA 2.1 left outer join

亡梦爱人 提交于 2019-12-05 03:33:52
I’m using JPA 2.1 and Hibernate 4.3.6.Final. I’m trying to use CriteriaBuilder to write a left outer join with conditions, so I have final CriteriaBuilder cb = m_entityManager.getCriteriaBuilder(); CriteriaQuery<Message> query = cb.createQuery(Message.class); Root<Message> messageRoot = query.from(Message.class); final Join<Message, Group> groupJoin = messageRoot.join(Message_.group); final Join<Message, MessageReadDate> msgReadDateJoin = messageRoot.join(Message_.messageReads, JoinType.LEFT); // form left outer join clause. msgReadDateJoin.on( cb.equal(messageRoot, msgReadDateJoin.get

JPA : applicationManaged EntityManager for Java SE to control transaction lifecycle programmatically

核能气质少年 提交于 2019-12-05 02:43:43
问题 I'm having difficulties finding a good solution to support this feature where the UI can start and commit the transaction. In my previous approaches in working with transactional applications, i group the unit of work into a service method in the backend , and annotate it with spring's @Transactional. But imagine that i have several service methods like this, and it's up to the frontend to group the service method calls within a transaction. For example, i have methodServiceA, methodServiceB,

Hibernate: switch from core API to JPA API without rewriting mapping

佐手、 提交于 2019-12-05 02:17:55
问题 Is it possible to use a hbm xml Hibernate configuration to build an EntityManagerFactory and EntityManager in a JPA 2.0-compliant manner? The documentation seems to indicate this isn't possible: "The previous tutorials used the Hibernate-specific hibernate.cfg.xml configuration file. JPA, however, defines a different bootstrap process that uses its own configuration file named persistence.xml." —Chapter 4 My hbm xml configuration is many thousands of lines long and works; I'd rather not have

JPA and Hibernate proxy behavior

筅森魡賤 提交于 2019-12-05 01:58:01
问题 i tried to observe JPA2 / Hibernate4 proxy behavior below, // Circular entity with lazy loading: @Entity public class Employee { @Id@Generated int id; String name; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) Employee boss; public String toString() { return id + "|" + name + "|" + boss; } //getters and setters ... } // Persist entities: // Outer entity: Employee employee = new Employee(); employee.setName("engineer"); // Inner entity: Employee boss = new Employee(); boss

If/Case statement in JPA Criteria Builder

[亡魂溺海] 提交于 2019-12-04 23:59:11
问题 I want to build up a query which search dates on different entites. My structure is: Contract has date (non nullable) Employee has date (non nullable) Employee may have a contract id (nullable) If a Employee has a contract I want to retrieve the contract date. If an employee does not have a contract then I want to return the Employee date. My code so far is: if (inputDate!= null) { ParameterExpression<Date> exp = criteriaBuilder.parameter(Date.class, "inputDate"); criteria.add(criteriaBuilder

selecting all rows from a database using JPA in WebSphere

随声附和 提交于 2019-12-04 22:57:25
I am trying to implement a web service that uses open JPA to access the data layer. I am using websphere v7.0 and JPA 2.0. This service is going to get all rows out of a small db (about 6 rows and it won't expand much at all in the future). I am attempting to get all rows and return them through the user. I am right now creating the Session Bean that will retrieve the data. I have several JPA objects one of them (representing a row of all the data I want to return) looks like so... @Entity @NamedQueries({ @NamedQuery(name="EmailDomainTrust.getEmailDomains", query="SELECT DOMAIN_NAME,"+

jpa FlushModeType COMMIT

十年热恋 提交于 2019-12-04 21:21:41
In FlushModeType.AUTO mode, the persistence context is synchronized with the database at the following times: before each SELECT operation at the end of a transaction after a flush or close operation on the persistence context In FlushModeType.COMMIT mode, means that it does not have to flush the persistence context before executing a query because you have indicated that there is no changed data in memory that would affect the results of the database query. I have made an example in jboss as 6.0: @Stateless public class SessionBeanTwoA implements SessionBeanTwoALocal { @PersistenceContext

Hibernate unidirectional OneToMany delete violates constraint ( optional=false at parent side?)

喜欢而已 提交于 2019-12-04 19:29:03
I use Hibernate 3.6 and I have something like this: @Entity public class Parent { @OnyToMany( fetch = FetchType.LAZY, cascade = { ascadeType.ALL } ) @Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE ) @JoinColumn( name="Parent_ID" ) public List<Child> getChildren() { return children; } public void setChildren( List<Child> children ) { this.children = children; } private transient List<TitleMetadataCategory> children; ... } @Entity public class Child { .... } Association is unidirectional for several reasons and I don't want to change it

JPA Criteria query Path.get left join is it possible

╄→гoц情女王★ 提交于 2019-12-04 19:16:12
问题 I have a question regarding JPA criteria. Here is my JPA criteria query: CriteriaBuilder criteriaBuilder = getEm().getCriteriaBuilder(); CriteriaQuery<InventoryItemSumReport> query = criteriaBuilder.createQuery(InventoryItemSumReport.class); Root<InventoryItemDetail> from = query.from(InventoryItemDetail.class); Join<InventoryItemDetail, InventoryItem> joinItem = from.join(InventoryItemDetail_.inventoryItem); Predicate where = criteriaBuilder.lessThanOrEqualTo(from.get(InventoryItemDetail_

JPA. How do I subclass existing entity and keep its ID?

只谈情不闲聊 提交于 2019-12-04 18:11:16
问题 Assume I have two classic non-abstract JPA classes: Person and Student. @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private String id; // ... } @Entity public class Student extends Person { // ... } Now person having some id enters the university and becomes a student. How do I process that fact in JPA and keep person's id? student = new Student(); student.setPersonData(person.getPersonData()); student.setId