jpa-2.1

Insert and update with CriteriaBuilder JPA in the same transactional method thows error “Foreign Key not exist”

大城市里の小女人 提交于 2019-12-08 14:52:31
问题 I am trying to make an insertion and with the resulting entity update N records in the same transaction. The error "FK does not exist" occurs and observing the log trace of the query is executed in the reverse order to which the instructions were triggered. Service: @Transactional public Entity1 createEntity(Entity1 newEntity){ Entity1 inserted = dao.createEntity(newEntity); Integer numUpdated = dao.updateEntity2(newEntity) return inserted; } Dao: public Entity1 createEntity(Entity1 newEntity

Unexpected token (START_OBJECT), expected VALUE_STRING: need JSON String that contains type id (for subtype of java.lang.Object)

纵然是瞬间 提交于 2019-12-08 08:45:35
问题 I already went through the below few links, but it did not solved my problem: Java Jackson: deserialize complex polymorphic object model: JsonMappingException: Unexpected token (START_OBJECT), expected VALUE_STRING Java Jackson - Unexpected token (START_ARRAY), expected VALUE_STRING In my project, we've 15 batch jobs. I am converting 15 batch jobs into 15 different micro-services. For that I have created one Spring Boot module, which has Entity classes, JPA repository layer and service layer.

EclipseLink deserializes an empty entity object on remote EJB call

﹥>﹥吖頭↗ 提交于 2019-12-08 04:14:20
问题 I am using the current release of GlassFish 4.1 with EclipseLink version 2.5.2 included. At this GlassFish, I have an enterprise application and a web application deployed. If an EJB that returns a loaded entity, is called from outside the GlassFish (like an external JavaFX application), the entity is returned properly. But if the same EJB is called from the web application, the entity is not returned properly due to this bug GLASSFISH-17432. The workaround I already found here Calling Remote

LocalDate between using JPA 2.1 Criteria API

让人想犯罪 __ 提交于 2019-12-08 02:35:28
In my entity I have two fields : private LocalDate startDate = LocalDate.of(1900, 1, 1); private LocalDate endDate = LocalDate.of(3000, 1, 1); Using JPA Criteria API I want to select entities where LocalDate.now() > startDate and LocalDate.now() < endDate . I tried as following : predicates.add(builder.greaterThan(LocalDate.now(), path.<LocalDate> get(Entity_.startDate))); predicates.add(builder.lessThan(builder.currentDate(), path.<LocalDate> get(Entity_.endDate))); But I get this error : The method greaterThan(Expression<? extends Y>, Expression<? extends Y>) in the type CriteriaBuilder is

JPA 2.1 ConstructorResult Causing ClassCastException

点点圈 提交于 2019-12-08 02:15:40
问题 The objects in my resultset are being cast to 'Object' instead of what I specified in the @SQLResultSetMapping objects. I'm trying to get a handle on ConstructorResult and have created a query which contains a simple join and am trying to get the result set and loop though it printing it out to make sure I have it right. However when I get to the loop what looks like it should be straight forward isn't. When I declare the result list it is cast to be of type . I step through the query test

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

我的未来我决定 提交于 2019-12-07 19:44:31
问题 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

JPA equivalent command to Hibernate.initialize

别等时光非礼了梦想. 提交于 2019-12-07 19:06:16
问题 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? 回答1: 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

optional parameters jpa 2.1

感情迁移 提交于 2019-12-07 15:26:14
问题 I have this class, @Entity public class Message { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private long id; @Column( nullable = false ) private String mobile; @Column( nullable = false ) private String message; @Column( nullable = false ) private Lang lang; @Column( nullable = false ) private int status; @Column( nullable = false ) private Calendar creationDate; ... } and I would like to be able to query the table with optional parameters from a form. I'm using JPA 2.1 and

How to convert SQL Query using CriteriaQuery

别来无恙 提交于 2019-12-06 15:53:48
问题 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

How to use JPA - EntityGraph to load only a subset of entity @Basic attributes?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 13:16:05
I found this documentation about entity-graphs... after read it, it gave me the idea that you can used entity-graphs to retrieve only a subset of @Basic fields of a given entity (Until now, I have used entity-graphs to retrieve relationships EAGERLY, i.e, for example, load an Employee[including all its attributes] and its associated Department[including all its attributes])... So, I decided to try this using a small test: @Entity @Table(name = "employee") @NamedEntityGraphs({ @NamedEntityGraph( name = "OnlyName", attributeNodes = @NamedAttributeNode(value = "name") ) }) public class Employee