jpa-2.0

Spring 3.1 JPA not inserting data while running in tomcat

拟墨画扇 提交于 2019-12-06 06:32:06
I have spent three days trying to find the solution to this problem to no avail. I am desperate to figure this out. I have a simple spring app, running in servlet 2.5 with jstl tags 1.2, running in tomcat with spring 3.1, using hibernate and the hibernate jpa implementation. I can list data from a page, but I cannot complete an insert. The record goes back, it appears to fire through with no problems. Yet no insert takes place. I know there are other posts similar but I have looked through them all and have not been able to find a solution anywhere. If I run the exact same code via a MAIN

How to pass parameter on jpa query?

痴心易碎 提交于 2019-12-06 06:23:05
I have two entities Like SmsOut and SmsIn . The relation between two entities contains OneToMany where smsIn.id is primary key and smsOut.sms_in_id is foreign key . Now I want to pass parameter like smsIn.mobileNumber , smsIn.smsText and so on, on the query SELECT so FROM SmsOut so order by id desc Following is my database diagram: Edited Following is my code : String sql = "SELECT so FROM SmsOut so WHERE so.smsInId.mobileNumber =:mobileNumber AND so.smsInId.smsText =:smsText AND so.smsInId.shortCode =:shortCode between so.smsOutDate =:startDate and so.smsOutDate =:endDate order by id desc";

JPA 2.0 Provider Hibernate 3.6 for DB2 v9.5 type 2 driver is throwing exception in configuration prepration

岁酱吖の 提交于 2019-12-06 06:19:34
The JPA 2.0 Provider Hibernate is throwing exception while preparing configuration for entity manager factory, I am using DB2 v9.5 database and DB2 v9.5 JDBC type 2 driver . java.sql.SQLException: [IBM][JDBC Driver] CLI0626E getDatabaseMajorVersion is not supported in this version of DB2 JDBC 2.0 driver. at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throwNotSupportedByDB2(Unknown Source) at COM.ibm.db2.jdbc.app.DB2DatabaseMetaData.getDatabaseMajorVersion(Unknown Source) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:117) at org.hibernate.cfg.Configuration

How can i inner join a subquery in JPQL

跟風遠走 提交于 2019-12-06 06:18:52
问题 I need a JPQL for the MySQL query: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.table1.id INNER JOIN (SELECT * FROM table1 t3 INNER JOIN table2 t4 ON t3.id = t4.table1.id WHERE t3.name = 'xxx') subTable ON t1.number = subTable.number WHERE t1.number = '5' AND id = '3' 回答1: Your query seems quite pathological, perhaps say what result you are trying to query, and include your object model. In general, JPQL does not support sub-selects in the from clause, so your query is not

JPA 2 Criteria API: why is isNull being ignored when in conjunction with equal?

时间秒杀一切 提交于 2019-12-06 06:13:10
I have the following entity class (ID inherited from PersistentObjectSupport class): @Entity public class AmbulanceDeactivation extends PersistentObjectSupport implements Serializable { private static final long serialVersionUID = 1L; @Temporal(TemporalType.DATE) @NotNull private Date beginDate; @Temporal(TemporalType.DATE) private Date endDate; @Size(max = 250) private String reason; @ManyToOne @NotNull private Ambulance ambulance; /* Get/set methods, etc. */ } If I do the following query using the Criteria API: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<AmbulanceDeactivation

JPA - using long array in IN operator throws cast exception

百般思念 提交于 2019-12-06 06:09:33
am new to JPA and am able to get it quickly, I had been trying a select query using "IN" operator in the query and had been getting the error as down. What I do is, i get a array of (long) message ids from a function and i use it to select the record based on those ids. Here is my query select t from MessageTable t where t.messageId IN (:id) query.setParameter("id", id); I had just shown you part of the code, in entity messageId is long and in Oracle DB its number. When i try as just as long variable it works, it doesn't seem to work when i pass long array. Had any one come across such a

JPA 2.0 subselect / subquery in order by clause with criteria api

て烟熏妆下的殇ゞ 提交于 2019-12-06 05:51:47
问题 I want to use JPA 2.0 criteria api to build the order by clause with a subselect. I know that you can do that in plain SQL but can it be mapped with criteria api? Can someone please give a code example? Example: Order(name, address) // table1 OrderPriority(address, priority) // table2 priority by address select o from Order o order by (select p.priority from OrderPriority p where p.address = o.address) 回答1: Criteria API queries are converted to JPQL and apparently subqueries in the order by

How to use EntityManager from @PrePersist?

不羁的心 提交于 2019-12-06 05:47:34
I have "post" entity/table with this "schema": @Id @GeneratedValue(strategy = GenerationType.AUTO) int id; @GeneratedValue(strategy = GenerationType.AUTO) private Integer postId; private Integer revisionId; private Boolean isCurrentRevision; So, table contains posts, each of them has multiple revisions, but only of them (for each post) is current. Now, let's say I want to persist another revision of existing post (i.e. update post): I need to find highest existing revisionId for this postId, increment it and set it to revisionId. Also this is the new current revision and so it should be marked

ON CASCADE DELETE on JPA2 many-to-many relationship

南楼画角 提交于 2019-12-06 05:38:35
问题 I have read a lot of topics regarding cascading and many-to-many associations, but I haven't been able to find an answer to my particular question. I have a many-to-many relationship between UserProfiles and Roles. When I remove a UserProfile I want the associated records in the join table (userprofile2role) to be removed by the database, so with an actual SQL 'ON DELETE CASCADE' action. Is this possible? Whatever I try, Hibernate always creates the UserProfile table without specifying ON

How to load a Hibernate 'xxx.hbm.cfg' file in a JPA 2.0 project?

非 Y 不嫁゛ 提交于 2019-12-06 03:47:21
问题 I have just started a Spring Roo application with Hibernate as a JPA2.0 provider. I am using the jars as follows: hibernate-core-3.6.4.Final.jar hibernate-commons-annotations-3.2.0.jar hibernate-entitymanager-3.6.4.Final.jar hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-validator-4.1.0.Final.jar I am using Annotations to handle the transactional aspect of the application, no problem there. But there are other parts of the application that require very complex queries, and the way I had it