FAQ Database Discussion Community


JPA: Using @MapKey for an abstract class

java,hibernate,jpa,eclipselink,jpa-2.0
I have the following structure of an abstract superclass A and a class Z referring to As sublasses B and C using a map: @Entity Abstract Class A @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; Integer map_field; <----------------------- Problematic .... @Entity Class B extends A @Id @GeneratedValue(strategy = GenerationType.AUTO) private...

How to retrieve nested data in JPQL?

jpa,jpa-2.0,jpql
working with OpenJPA2 persistence. I have a very simple entity class, that does have a String property and a List property. I do persist its instances flawlessly with the nested List (in a JSF2 web project). I check the database and there appears two tables (I use automatic schema generation),...

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...

What's the difference between “JOIN FETCH” and “JOIN”?

jpa,jpa-2.0
Supposing I have a Person entity that has @OneToMany relationship with Phone entity. If I want to eagerly fetch Phone entities associated with a Person, I got 2 options: SELECT p FROM Person p JOIN p.phones or SELECT p FROM person p JOIN FETCH p.phones So what is the difference...

OneToOne PrimaryKeyJoinColumn Cascade

hibernate,jpa,eclipselink,jpa-2.0
I am struggling a little bit to make Eclipselink to cascade persist a relationship: @Entity class Notification { @Id @UuidGenerator(name="UUID_GEN") @GeneratedValue(generator="UUID_GEN") @Column(name = "NOTIFICATION_ID") private UUID id; @OneToOne(cascade = ALL, fetch = FetchType.EAGER) @JoinFetch(JoinFetchType.INNER) @PrimaryKeyJoinColumn(name="NOTIFICATION_ID", referencedColumnName="NOTIFICATION_ID") private Notificator notificator; ... } @Entity class Notificator { @Id @Column(name="NOTIFICATION_ID") private UUID id;...

JPA 2.0 EntityManager merge remove a reference do nothing

java,spring,jpa,merge,jpa-2.0
i'm trying to remove a child from a parent entity (without delete the reference from the DB) using merge, what i do is get the collection of a @OneToMany field from the parent and then remove from the collection and finally i use merge, this works when i use the...

Unknown column 'categories1_.category' in 'field list'

spring,hibernate,jpa-2.0,spring-data,spring-data-jpa
I have the following model. Employee.Java @Entity public class Employee { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @Column(name="firstName") private String firstName; @Column(name="lastName") private String lastName; @Column(name = "category") @Enumerated(EnumType.STRING) @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "myobject_categories", joinColumns = @JoinColumn(name = "myobject_id")) private Set<Category> categories; } Category is an Enum as follows. public...

hibernate delete second level jpa2.0

java,hibernate,jpa-2.0,hibernate-cache
I need in my application to remove all data from a cachable table. I suposed that to delete all contents, I had to remove the second level cache, then use a truncate. @Entity @Table(name = "\"cpf_formacode\"") @Cacheable public class CpfRefFormaCode implements Serializable { ....... } the Dao method: public void...

OpenJPA OneToMany and composite key in parent and child table

java,jpa,jpa-2.0,openjpa
I have tables with composited primary key. Server(key=ServerId) ServerId|Name 1 |server1 2 |server2 ParentObj(key=ServerId+Code) ServerId|Code |Title 1 |code1|value1 1 |code2|value2 2 |code1|Value2b ChildObj(key=ServerId+Code+Name) ServerId|Code |Name |Value 1 |code1|prop1|val1 1 |code1|prop2|val2 1 |code2|prop1|val1b 2 |code1|prop3|val3 This is Java beans I have. @Entity @Table(name="ParentObj") @Access(AccessType.FIELD) @IdClass(value=ParentObj.PK.class) @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) @XmlRootElement public class ParentObj {...

JPA left outer join using CriteriaBuilder results in error: Partial object queries are not allowed to maintain the cache or be edited

java,jpa,eclipselink,jpa-2.0,criteria-api
I have the following entity relationships Product @Entity @Table(name="PRODUCTS") public class Product @Id @Column(name="product_id") private long productId; @ManyToOne @JoinColumn(name="EMP_NUMBER") private Employee employee3; .... .... Employee @Entity @Table(name="EMPLOYEES") public class Employee @Id @Column(name="EMP_NUMBER") private String empNumber; @Column(name="EMP_NAME") private String employeeName; @OneToMany(mappedBy="employee3") private List<Product> Product3; .... .... In DAOImpl class I have...

print the fileds which has a specific annotation in a Java class

java,jpa-2.0
In my model there are different persistent fields which have different annotation such as @Column, @OneToMany , etc. @OneToMany(mappedBy = "Clinte", cascade = CascadeType.ALL, orphanRemoval = true) private Set<Takeover> takeovers = new HashSet<Takeover>(); @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "CAR_ID") private Car carID; @Column(length = 50, name =...

How can I sort on the results of a case statement in Spring Data?

java,jpa-2.0,spring-data,spring-data-jpa,criteria-api
we have a UI sortable table that is backed by the following query, clicking a column does order by ascending or descending on that column. Problem is that one of the columns either renders the the users role name or their human name dependent on a conditional, and we need...

jpa 2 CriteriaQuery do not discriminate child entities

hibernate,jpa-2.0,criteriaquery
I have an entity which have a relation of one to many with another entity. say 1A -> 1.*B i wrote this query. CriteriaBuilder cb = super.getEntityManager().getCriteriaBuilder(); CriteriaQuery<A> select = cb.createQuery(A.class); Root<A> from = select.from(A.class); Join<A, B> joinB = from.<A, B>join("b"); select.select(from); select.where( cb.between(joinB.<Date>get("date"), dateA, dateB) ); the problem: The...

Multiple Spring Data JPA repositories in single transaction

spring,jpa,orm,jpa-2.0,spring-data
I am trying to map the following code: * Order contains many OrderItems * Article can be referenced by (contains) many OrderItems In one transaction I need to create Order, several Articles and OrderItems with the new articles. All is clear when there is straigth path - Order contains OrderItems...

JPA Hibernate PostgreSQL current_date doesn't work

hibernate,postgresql,playframework,jpa-2.0
I have a PostgreSQL 9.3.6 database with the following query defined: CREATE OR REPLACE VIEW calls_today AS SELECT cc.* FROM call_config cc WHERE cc.created_at >= current_date; The view is used on the web portal developed with Play Framework + Hibernate via JPA 2. Everything seems to work fine except the...

JPA 2.0 - Persist child entity automatically on Parent persist, giving org.hibernate.id.IdentifierGenerationException

hibernate,jpa-2.0
I have two entities named Customer and his Biiling Address. The relationship is one to one. Every customer has exactly one billing address. I want to persist billing address automatically when customer is persisted. The customer id is primary key of Customer entity and it is also primary as well...

JPA base64 generator

java,hibernate,jpa,persistence,jpa-2.0
How can I define base64 generator for the value based on id? for example, I have an entity: @Entity class Test{ @Id @GeneratedValue(strategy = GenerationType.AUTO) int id; //here should be the assigned value encoded to base64 based on id String value; } ...

JPA2 get column metadata (type, lenth, nullable, etc)

hibernate,jpa-2.0
title says it all, I'm working on a JPA2 (through Hibernate 4.0) based data layer that needs to be database agnostic, and I'm trying to retreive whether a column of a table (associated with an @Entity) is nullable, what the type is, and most importantly, if it's a varchar, how...

Can Nested or Inner class by an @Entity in JPA?

nested,jpa-2.0
Can I and Should I make nested, inner classes an @Entity? For example: @Entity public class EnclosingOne { @Entity public class NestedOne extends EnclosingOne { } @Entity public static class InnerOne extends EnclosingOne { } } Or: public class EnclosingOne { @Entity public class NestedOne extends EnclosingOne { } @Entity...