jpa-2.0

ManyToOne relation with composite key

折月煮酒 提交于 2020-01-06 14:17:07
问题 I have legacy database which entities were mapped using composite key. I converted the tables into entities with Eclipse JPA Tools but the received entities are not working. During Tomcat startup I receive the exception: referencedColumnNames(PETROL_STATION_ID, PROVIDER_ID) of xxx.FuelCardEntity.petrolStationInfo referencing xxx.PetrolStationInfoEntity not mapped to a single property Composite key class: @Embeddable public class PetrolStationInfoEntityPK implements Serializable { private

JPA criteria query with subquery

妖精的绣舞 提交于 2020-01-05 12:29:06
问题 I was wondering if it was possible to express the following query with jpa 2.0 criteria api. simple_table: user_name(varchar), bytes_total(bigint), time_total(bigint) >select user_name, sum(bytes_total), sum(bytes_total) * 100 / (select sum(bytes_total) from simple_table), sum(time_total), sum(time_total) * 100 / (select sum(time_total) from simple_table) from simple_table group by user_name I have everything working except for the two sub-queries. I would like to know whether or not this is

JPA 2 Criteria - using “in” and subqueries(?)

自作多情 提交于 2020-01-05 07:27:38
问题 I have a trouble with creating JPA 2 query (actually I'm using Spring Data JPA). I have a 2 tables: - Users (id,company_id,name,surname,status) - UsersGroup (id,user_id,group_id). Users can(and often are) connected to more than one group. What I'm trying to do is to get distinct list of users according to filtering options from search form (name,surname,status) and attributes taken from logged user (company_id, group_id), because I want to show this user only users within company and group he

Advantage of using JPAMetaModelEntityProcessor?

淺唱寂寞╮ 提交于 2020-01-04 14:12:01
问题 I just went through below link. http://hop2croft.wordpress.com/2011/07/07/criteria-jpa-2-0-and-database-metamodel-auto-generation-with-maven/ what is the advantage of using JPAMetaModelEntityProcessor ? Thanks! 回答1: In short, having a meta model of your entities available at compile time helps you reduce the number of run-time errors. Specifically, with a meta model you may (list is by far not exhaustive) ensure the syntactical correctness of a broader range of queries at compile time

How to access EntityManager inside Entity class in EJB3

牧云@^-^@ 提交于 2020-01-04 05:27:17
问题 I need to execute a db query inorder to set the extra column "The order by column" in a many to many association table. so I need to access the db sequence from inside the Entity class and and select the nextval of the sequence and assign it to the order_by column in @prepersist lifecycle callback method. @Entity public class ProductWishlist implements Serializable { .... @Column(name="ORDER_BIT") private long orderBit; // getter setter // ....... @Prepersist public void setOrderBit

How to use @Entity attribute when inheritance is across separate JARs?

微笑、不失礼 提交于 2020-01-04 05:12:07
问题 I have two entities where one of them inherits the other one, so I have in jar1 the entity1 and I have a jar2 the entity2->inherits(entity1) in jar1: @Entity public class Entity1 {...} in jar2: @Entity public class Entity2 extends Entity1 {...} So how can I make this to work, it doesn't even compile saying: An annotation processor threw an uncaught exception... Caused by: java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor

How to combine manual insert and JPA Id generation?

佐手、 提交于 2020-01-04 03:11:08
问题 I am running in-container tests with arquillian. I am prepopulating the database by adding an import.sql to the deployment. During the test I would like to create some more entities. Unfortunately, this fails with a PersistenceException : javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Unique index or primary key violation: "PRIMARY_KEY_BE ON PUBLIC.KVS_MIPO_DOWNLOAD(ID)" If I do not prepopulate the DB, or do not persist new entities, everything

Hibernate/hsqldb 2 Cannot Hydrate Blob Column

谁都会走 提交于 2020-01-04 01:56:11
问题 I am trying to load an entity with byte data (annotated with @Lob) from an HSQL 2.0 database using Hibernate 3.5.6. This entity is able to be saved without any problems and is loaded fine if it is in the cache (i.e. does not need to be hydrated). However, when the entity is not in the cache (needs to be hydrated), I receive the following exception: Caused by: org.hsqldb.HsqlException: incompatible data type in conversion: from SQL type BLOB to [B, value: instance of org.hsqldb.types

Got Null when querying datastore by key

拟墨画扇 提交于 2020-01-03 18:56:30
问题 I have two models, Book and Chapter, in a one-to-many relationship. I manually create the keys for both Book and Chapter. To persist, I create a book object then add an instance of chapter to it and then persist book. This works fine, as I see them in the datastore. Now when I try to fetch a chapter from the datastore by key, I get a null object. Here is how the keys look in the datastore: Under Book: name/id = 123 chapters = [Book(123)/Chapter("abc")] Under Chapter: name/id = abc I created

JPA query timeout parameters ignored but @Transaction annotation works

故事扮演 提交于 2020-01-03 17:17:04
问题 I want JPA queries made by my Spring Boot application to a Postgres database to timeout after 5 seconds. I have created this 20 seconds query to test timeouts: @Query(value = "select count(*) from pg_sleep(20)", nativeQuery = true) int slowQuery(); I've set the following properties in application.config : spring.jpa.properties.javax.persistence.query.timeout=3000 javax.persistence.query.timeout=5000 But the query does not timeout after 3s or 5s (it still takes 20s to execute). Strangely, if I