jpa-2.1

JPA equivalent command to Hibernate.initialize

久未见 提交于 2019-12-06 11:45:49
I have a Lazy collection that I want to initialize at will in my service/controller. At this moment I can do: Hibernate.initialize( myEntity.getListOfThings() ); This command is hibernate dependent and does not make the implementation of JPA transparent. Is there a JPA elegant way of doing this? Master Slave No, there's no JPA equivalent. You can learn if the object is loaded and than use one of the two options, either accessing the properties while the object is still attached to persistence context, what I typically see is calling size, just for the sake of initializing the collection

Constructor queries on a non-persistent entity unexpectedly fail to supply a Boolean parameter as a constructor argument

 ̄綄美尐妖づ 提交于 2019-12-06 04:48:14
There are two tables in MySQL database user_table feedback The relationship between them is intuitive - one to many from user_table to feedback . I need to fetch only a list of selected columns from these tables which are From feedback feedbackId (java.lang.Long) feedbackTitle (java.lang.String) feedbackDescription (String, decorated by @Lob ) feedbackDate (org.joda.time.DateTime) testimonial (java.lang.Boolean) From user_table userId (java.lang.Long) firstName (java.lang.String) These many fields out of many others are required to get by executing a query. The criteria query is as follows.

JPA 2.1 NamedSubgraph in Hibernate ignoring nested subgraphs

我的梦境 提交于 2019-12-06 01:56:58
问题 I'm using Hibernate 4.3.8.FINAL and have the following model where a Department has many Employees, and an Employee can be a Manager. Manager has a set of Foo which can be either Foo or Bar. The Employee entity: @Entity @Table(name = "employee", schema = "payroll") @Inheritance(strategy = InheritanceType.JOINED) public class Employee { @Id private Long id; @Basic(optional = false) @Column(name = "name") private String name; @JoinColumn(name = "department_id", referencedColumnName = "id")

Envers: Unidirectional OneToMany without additional audit table?

那年仲夏 提交于 2019-12-06 00:16:47
问题 The following database schema: Employee[EMP_ID (PK), name, salary] Phone[ID (PK), number_str, OWNER_ID (FK)] Employee_aud[EMP_ID (PK), REV (PK/FK), REVTYPE, name, salary] Phone_aud[ID (PK), REV (PK/FK), REVTYPE, number_str] Employe_phone_aud[REV(PK/FK), OWNER_ID(PK/FK), REVTYPE(PK/FK)] can be expressed with the following Java Entities: Employee : @Entity @Audited public class Employee { @Id @GeneratedValue @Column(name = "EMP_ID") private long id; @Column private String name; @Column private

JPA2 Criteria and Java 8 Date&Time API

£可爱£侵袭症+ 提交于 2019-12-05 21:18:50
问题 I try to port a Java web application to the new Java 8 Date&Time API (using 'LocalDate' and 'LocalDateTime' types among others) In Java 7, java.util.Date could be used in JPA2 criteria API to filter result sets on dates. Typically one would do this by adding a predicate e.g. .. predicatesList.add(builder.between(from.get(AccountLog_.valueDate), fromDate, toDate)); .. Now JPA2 doesn't support the new Java 8 Date&Time API (LocalDate and LocalDateTime) yet. With own "Attribute Converters",

Spring boot Hibernate error java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

落爺英雄遲暮 提交于 2019-12-05 20:42:12
I am doing a prototype using Spring Boot on an existing project with many Hibernate dependencies. I am trying to define a custom LocalEntityManagerFactoryBean and it is here that I get this error: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; I have tried updating my hibernate versions (could not use all latest versions due to project backward compatibility causing many other compile errors) but with the following hibernate dependency graph could get it to compile but still get this runtime dependency error. When I searched for this error

@ConstructorResult mapping in JPA 2.1 does not work properly with Hibernate 4.3.5.Final

久未见 提交于 2019-12-05 19:40:07
I try to map a native query to a non-Entity class. I have the following Entity: @Entity @Table(name = "Groups") @SqlResultSetMapping(name = "groupList", classes = { @ConstructorResult(targetClass = GroupListEntry.class, columns = { @ColumnResult(name = "id", type = Long.class), @ColumnResult(name = "name", type = String.class), @ColumnResult(name = "typeId", type = Long.class), @ColumnResult(name = "lastUpdateDate", type = Date.class) }) }) public class GroupEntity implements Serializable { ... } I expected that calling final Query query = getEntityManager().createNativeQuery(q.toString(),

JPA 2.1: Introducing Java 8 Date/Time API

时间秒杀一切 提交于 2019-12-05 01:46:24
I'd like to add support for the Java 8 Date/Time API (JSR-310) in my JPA-enabled application. It's clear that JPA 2.1 does not support the Java 8 Date/Time API . As a workaround, the most common advise is to use an AttributeConverter . In my existing application, I changed my entities to use LocalDate / LocalDateTime types for the column mapping fields and added legacy setter/getters for java.util.Date to them. I created corresponding AttributeConverter classes. My application does now fail when using Query.setParameter() with java.util.Date instances (it worked before the transition to the

How to convert SQL Query using CriteriaQuery

泪湿孤枕 提交于 2019-12-04 23:14:27
I want to convert my sql query from SQL to CriteriaQuery, I have this sql query: 1) SELECT * FROM table AS t WHERE id = (SELECT MAX(id) FROM table AS t WHERE t.element_id = 354 AND (name <> 'foo' OR (name = 'bar' AND event = 'foo'))); 2) SELECT tr1.* FROM table AS tr1 INNER JOIN (SELECT MAX(id) AS id FROM table AS tr WHERE tr.element_id = 354 AND (name <> 'foo' OR (name = 'bar' AND event = 'foo'))) AS tr2 ON tr1.id = tr2.id; How is the best way to do this ? public Predicate createsubqueryDateGreaterThanTest(CriteriaBuilder cb, Root<? extends Entity> root, Date inputDate){ // create the outer

@OnDelete Hibernate annotation does not generate ON DELETE CASCADE for MySql

久未见 提交于 2019-12-04 15:04:32
I have two entities parent and child with a unidirectional relationship class Parent { @Id @GeneratedValue(strategy= GenerationType.AUTO) private Long id; } and class Child { @Id @GeneratedValue(strategy= GenerationType.AUTO) private Long id; @ManyToOne(optional = false) @JoinColumn(name = "parent_id") @OnDelete(action = OnDeleteAction.CASCADE) private Parent parent; } In the application.properties file I have configured spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.database-platform = org.hibernate.dialect.MySQL5InnoDBDialect But when I run the