jpa-2.0

JPA table with 2 primary key fields

纵然是瞬间 提交于 2019-11-30 03:54:14
I have a table which contains only 2 fields. The table has a composite PK formed by these two fields. When using Netbeans for creating entity beans from database, the entity bean is not created automatically like other tables that have more than 2 fields. So I guess I need to create the entity bean myself. What is the best practice for creating this entity bean? Does it have to contain COMPOSITE KEY object or not? Xavi López I don't use NetBeans so I can't really say anything about its mapping tools. For mapping a composite key, there are a couple of options. You can Define a separate

How to define an non-JTA datasource for JPA-Hibernate? org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource:

*爱你&永不变心* 提交于 2019-11-30 03:35:14
问题 I am trying to change my web-app's JDBC code to JPA using Hibernate as provider. I am using Eclipse IDE. In that i have defined a MySQL data source. I added it in the persistence.xml. But, I am getting the below error. 6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: tamSql javax.naming.NameNotFoundException; remaining name 'tamSql' My persistence.xml looks like, <?xml version="1.0" encoding="UTF-8"?> <persistence version=

A concise, clear list of what is new in JPA2?

房东的猫 提交于 2019-11-30 02:54:53
Does anybody know of a good list of what is new in JPA 2? Not what is new with Hibernate/TopLink in the version that supports JPA 2 but what is new in the actual spec. The link mentioned in the accepted answer doesn't say anything about the second level cache so I decided to post a quick list to summarize "What's new in JPA 2.0 (JSR-317)": Standard properties for persistence.xml - E.g. javax.persistence.jdbc.driver , etc instead of persistence provider specific properties. Mixed Access Type - PROPERTY and FIELD access type can be mixed in a hierarchy and combined in a single class. Derived

Initializing a transient attribute of a JPA entity during CriteriaQuery

老子叫甜甜 提交于 2019-11-30 02:36:43
问题 I'm wondering if it is possible to initialize a transient attribute of an entity during a criteria query. Example @Entity public SampleEntity{ @Id private long id; [more attributes] @Transient private String someTransientString; [getters and setters] } Now I want to compose a CriteriaQuery that loads all SampleEntity s and automatically sets someTransientString to imamightlyfinestring . I have something like the following SQL in mind: SELECT ID AS ID, [..], 'imamightilyfinestring' AS SOME

JPA 2 No explicit selection and an implicit one cold not be determined

ⅰ亾dé卋堺 提交于 2019-11-30 01:58:59
问题 I am trying to fetch all users for a folder where the user was created after a certain date. the relationship between the user and the folder lives in a seperate table. This is the query I came up with but it thorws the exception No explicit selection and an implicit one cold not be determined The code @Override public List<RetailPostUserTbl> getNewUsersForSiteSince( Date date, Integer siteId ) { List<RetailPostUserTbl> toReturn = new ArrayList<RetailPostUserTbl>(); EntityManager em =

Class not eligible for getting processed by all BeanPostProcessors

喜夏-厌秋 提交于 2019-11-30 01:35:53
I'm having a lot of trouble to set up a configuration of Spring + Spring Data JPA + QueryDSL + JPA 2.0 + Hibernate in Maven. I already solved a lot of problems, but this one is giving me headache =/. I'm getting the following exception: Bean 'dataSource' of type [class org.springframework.jdbc.datasource.DriverManagerDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) I took a look in Google and most of times this problem is caused by the absence of the annotation "@Transactional". I tried to annotate my methods, but it didn

Is Select EXISTS() possible in JPQL?

若如初见. 提交于 2019-11-30 00:45:18
问题 I'm trying to run a query that checks if some conditions are true and returns a simple boolean result as output. What makes it slightly tricky is that one of the conditions is to test for whether no results are returned for a set of criteria. I'm currently using JPA-2.0 with hibernate as my provider, backed by MySQL. I have gotten an example query working fine in MySQL, but when trying to get it running in JPQL it flops. The MySQL query looks a bit like this: Select exists(Select statement

@OneToOne(optional=false) and @JoinColumn(nullable=false) used together

*爱你&永不变心* 提交于 2019-11-30 00:25:26
I've bumped into this example in JPA 2.0 FR Specification, 11.1.37. OneToOne Annotation, page 403: @OneToOne(optional=false) @JoinColumn(name="CUSTREC_ID", unique=true, nullable=false, updatable=false) public CustomerRecord getCustomerRecord() { return customerRecord; } Is there any reason that I should put @OneToOne(optional=false) and at that same time put @JoinColumn(... nullable=false) ? Aren't these two declarations the same? Isn't one of them redundant? Are both of them used in DDL schema generation? Formally optional=false is a runtime instruction to the JPA implementation, and nullable

JPA ManyToMany Join Table has all attributes as PK

吃可爱长大的小学妹 提交于 2019-11-29 22:57:06
问题 I'm using Hibernate 3.3.1 and am following along in modelling this sample table structure, but I'm having trouble creating a join table with extra attributes. It's the many-to-many relationship between the Order and Product table. The join table is the Order Detail table. I followed the approach mentioned here. Now I have the entities @Entity @Table(name = "Orders") public class Order { @OneToMany(mappedBy="order") private List<OrderDetail> orderItems; } and @Entity @Table(name="PRODUCTS")

org.hibernate.QueryException: illegal attempt to dereference collection

百般思念 提交于 2019-11-29 22:47:46
I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference collection [billdetail0_.bill_no.billProductSet] with element property reference [product] [select count(*) from iland.hbm.BillDetails as bd where bd.billProductSet.product.id=1001 and bd.client.id=1] at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:68) at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java