jpa-2.0

Hibernate/JPA not validating against DB schema on startup

蓝咒 提交于 2019-12-10 17:46:22
问题 For some reason hibernate is not catching issues like mapping entities to tables that do not exist. My persistence.xml file looks like this... <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <!-- A JPA Persistence Unit --> <persistence-unit name=

JPA date literal

偶尔善良 提交于 2019-12-10 17:17:34
问题 How represent a date in a JPA query, without using (typed) parameters? If the date is really fixed (for example, 1 mar 1980), the code: TypedQuery<MyEntity> q = em.createQuery("select myent from db.MyEntity myent where myent.theDate=?1", db.MyEntity.class).setParameter(1, d); having set: Date d = new Date(80, Calendar.MARCH, 1); is quite verbose, isn't it? I would like to embed 1980/1/3 into my query. UPDATE: I modified the sample date to 1980/1/3, because 1980/1/1 as it was, was ambiguous.

Casting Integer to String in JPQL

左心房为你撑大大i 提交于 2019-12-10 14:15:20
问题 I want to have a JPQL query that may look like: entityManager.createQuery("Select a.* from A a WHERE CAST(a.num AS TEXT) LIKE '%345%' ", A.class); where a.num is an integer. I want to cast this to String to use the LIKE criteria. However above casting doesnt work in JPQL. Any idea about how can I implement this? 回答1: Could you be more specific, what your problem is? Do you have some kind of error or it the result of the query is just wrong? Because this code works fine for me: session

javax.ejb.EJBException when persisting an entity

。_饼干妹妹 提交于 2019-12-10 13:32:30
问题 I have an entity called Medico which was created as an Entity Class from Database, hence I think the entity definition is failsafe here, nevertheless the definition is the following: @Entity @Table(name = "medico") @XmlRootElement @NamedQueries({All named queries here}) public class Medico implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "idMedico") private

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

这一生的挚爱 提交于 2019-12-10 11:14:58
问题 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

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

那年仲夏 提交于 2019-12-10 10:55:30
问题 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

Lazy loading exception when using JSF Converter (refering to a collection)

∥☆過路亽.° 提交于 2019-12-10 10:18:38
问题 This is my first post after many research on this problem. This example is running under Jboss 7.1 with seam 3.1 (solder + persistence + faces) with seam managed persistence context I'm facing a problem, the classical failed to lazily initialize a collection, no session or session was closed: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed when using a converter on Entity beans. The aim is to stay 100% Object oriented, by

JPA 2.0 Criteria and grouping of Predicates

北战南征 提交于 2019-12-10 03:57:58
问题 I encounter problem with Hibernate EntityManager 3.5.3-Final when it comes to composite predicates. Example (not actual code snippet, but the idea should be clear): CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Predicate predicate1 = criteriaBuilder.conjunction(); Predicate predicate2 = criteriaBuilder.conjunction(); // These are Boolean expression with common Root predicate1.getExpressions().add(expression1); predicate1.getExpressions().add(expression2); predicate2

Getting “with clause can only reference columns in the driving table” when trying to write a JPA 2.1 left outer join

懵懂的女人 提交于 2019-12-10 03:12:34
问题 I’m using JPA 2.1 and Hibernate 4.3.6.Final. I’m trying to use CriteriaBuilder to write a left outer join with conditions, so I have final CriteriaBuilder cb = m_entityManager.getCriteriaBuilder(); CriteriaQuery<Message> query = cb.createQuery(Message.class); Root<Message> messageRoot = query.from(Message.class); final Join<Message, Group> groupJoin = messageRoot.join(Message_.group); final Join<Message, MessageReadDate> msgReadDateJoin = messageRoot.join(Message_.messageReads, JoinType.LEFT)

Hibernate ordering in sql

核能气质少年 提交于 2019-12-10 00:25:18
问题 Is it possible to sort the Set collection using hibernate, in sql without using SortedSet interface, without using @OrderBy annotation - just using criteria's addOrder. I've tried it and it adds order by clause but the set isn't sorted. I use hibernate 3.4. 回答1: NHibernate Sets don't have "order" even though the set mapping supports an order-by. See Ayende's explanation: Note that [order-by] does not work with generic sets and that in general, you don’t want to rely on those ordering