FAQ Database Discussion Community


Criteria API and Entity Graph

java-ee,criteria-api,jpa-2.1
I have two entities with unidirectional lazy relations. And one of them has a named entity graph. Here are the entities (getters and setter are not listed due to readability): @Entity @NamedEntityGraph ( name = "Sms.fetchSims", attributeNodes = { @NamedAttributeNode("sim") } ) public class Sms { @Id @GeneratedValue (strategy =...

JPA 2.1 Attribute Converter convert enum still insert int

java,spring-data,spring-data-jpa,jpa-2.1
i'm using spring data jpa with hibernate as provider. i'm trying to persist my enums on varchar(enum.tostring) instead of (0,1,2) my enum class: public enum MagasinType { PRINCIPAL { @Override public String toString() { return "Principale".toUpperCase(); } }, SECONDARY { @Override public String toString() { return "Secondaire".toUpperCase(); } }, MOBILE...

named stored procedure query Collection parameter?

java,jpa,stored-procedures,jpa-2.1
I'm using JPA-2.1 and want a stored procedure and with a Collection as a parameter. Is this possible? <named-stored-procedure-query name="myProc" procedure-name="my_proc"> <parameter name="i_collection" class="Collection" mode="IN"> </parameter> </named-stored-procedure-query> With the above I get a java.lang.ClassNotFoundException. If not, where is the documentation about what is allowed in the class attribute?...

Hibernate fails to load JPA 2.1 Converter when loaded with spring-boot and spring-data-jpa

java,hibernate,spring-boot,spring-data-jpa,jpa-2.1
I have a custom converter for UUID to transfer it to a string instead a binary: package de.kaiserpfalzEdv.commons.jee.db; import javax.persistence.AttributeConverter; import javax.persistence.Converter; import java.util.UUID; @Converter(autoApply = true) public class UUIDJPAConverter implements AttributeConverter<UUID, String> { @Override public String convertToDatabaseColumn(UUID attribute) { return attribute.toString(); } @Override public UUID convertToEntityAttribute(String dbData) { return...

RCP Editor and JPA merge

eclipse,jpa,eclipse-rcp,eclipselink,jpa-2.1
I am updating an RCP based application to use JPA 2.1 (EclipseLink's implementation) from Hibernate 3.x. The JPA merge behavior is causing me problems. The issue I am seeing is when I assign the returned value to the model object in the RCP editor (inherited from FormEditor) it is a...

JavaFX and JPA2 don't compile

java,javafx,jpa-2.1
I'm trying to use JPA2 for the persistence of a classes and write the GUI with javaFX. But at the compile time I get this error (with EclipseLink library): An annotation processor threw an uncaught exception. Consult the following stack trace for details. java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for sun.util.logging.PlatformLogger not...

Cascade types in JPA

hibernate,jpa,eclipselink,cascade,jpa-2.1
Given two entities Department and Employee forming a one-to-many relationship from Department to Employee. Since the relationship is quite intuitive, I am leaving out the entity classes. In Department : @OneToMany(mappedBy = "department", fetch = FetchType.LAZY) private List<Employee> employeeList = new ArrayList<Employee>(0); In Employee : @ManyToOne(fetch = FetchType.LAZY) private Department...

Hibernate Criteria aPI Multiselect

java,hibernate,postgresql-9.2,java-ee-7,jpa-2.1
If I use Hibernate Criteria API like: CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(); Root<OneEntity> entityOneRoot = criteriaQuery.from(OneEntity.class); Root<TwoEntity> entityTwoRoot = criteriaQuery.from(TwoEntity.class); criteriaQuery.multiselect(OneEntity, TwoEntity); Do I need to use EQUAL-restriction (as ON-restriction in SQL) for equaling IDs between both tables (entities)? Because of Cartesian product of both tables?...

Bidirectional relationships in JPA

hibernate,jpa,eclipselink,jpa-2.1,bidirectional-relation
I am missing something very fundamental. Given below two entities Department (inverse side) and Employee (owning side) forming a one-to-many relationship from Department to Employee. Department.java @Entity @Table(catalog = "testdb", schema = "", uniqueConstraints = { @UniqueConstraint(columnNames = {"department_id"})}) public class Department implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional...

JPA Create Parent/child relationship with a lot of children

postgresql,ejb,postgis,jpa-2.1,hibernate-spatial
I am trying to store entity Track with children entities TrackPoints with JPA method create. However, to store Track with its children TrackPoints last really long - about 30 seconds. I tried GenerationType.Identity and GenerationType.SEQUENCE. If I also have Hibernate Spatial (Postgis) column, it lasts even longer - about 60...

JPA first level cache not clreared after completion of transaction

jpa,jpa-2.0,jpa-2.1
I am using JPA 2.1(with EclipseLink implementation), to get a record from Database. By default it first level cache is enabled, it caches the record in PersistenceContext. If I try to get same record I will get it from first level cache, so no query will be fired on database...

org.hibernate.MappingException despite JPA Converter is available

hibernate,jpa,jpa-2.1
I've got a own Id type public class Id<T extends AbstractEntity<T>> {} and a JPA Attribute Converter: @Converter(autoApply = true) public class IdConverter<T extends Entity<T>> implements AttributeConverter<Id, Long> { //... } despite that I use @Converter(autoApply = true) and @Convert(...) at the property, I get a mapping exception when I...

order by when using Constructor Expressions in JPA 2

java,hibernate,jpql,jpa-2.1
As a part of JSR-338 came the feature of using Constructor Expressions. The question is how I can use order by when using Constructor Expressions. Given the example JPQL: select com.acme.AggregatedInfo( c, (select status from Account where ssn = c.ssn) ) from Customer c where m.id in (:customerIdList) And the...

Custom query within JPA server-managed session

jdbc,jta,websphere-liberty,jpa-2.1,jdk6
I'm trying to execute an unrelated query (other_table) within a JTA session (server-managed) in order to do some validations, before persisting the bean EJB into DB with JPA. Here is what I want to do (aprox): @PersistenceUnit(unitName="DynamicDatabase") EntityManagerFactory emf; @TransactionAttribute(TransactionAttributeType.REQUIRED) private long nextEntryid() { em = emf.createEntityManager(); Query query =...