jpa-2.0

How to apply @OneToMany on super class getter method in multiple subclasses with different target entity

半城伤御伤魂 提交于 2019-12-25 14:40:25
问题 Stack I'm using JPA2.0 with Eclipselink 2.6.3 and Spring 4(JTA). Problem I'm trying to override the class A attribute with @OneToMany mapping in class B and class C (which is similar to class B ) so that I can change the target entity to class X and Z respectively while fetching results for class B. Class A has SINGLE_TABLE inheritance and class B & C are discriminator classes which is maintained by @classExtractor depending on some field value in class A. Class Z has TABLE_PER_CLASS

How to apply @OneToMany on super class getter method in multiple subclasses with different target entity

百般思念 提交于 2019-12-25 14:40:03
问题 Stack I'm using JPA2.0 with Eclipselink 2.6.3 and Spring 4(JTA). Problem I'm trying to override the class A attribute with @OneToMany mapping in class B and class C (which is similar to class B ) so that I can change the target entity to class X and Z respectively while fetching results for class B. Class A has SINGLE_TABLE inheritance and class B & C are discriminator classes which is maintained by @classExtractor depending on some field value in class A. Class Z has TABLE_PER_CLASS

JPA2 and hibernate - why does merge store child entities whilst persist does not?

ε祈祈猫儿з 提交于 2019-12-25 08:28:26
问题 I have the usual parent - child OneToMany relationship: @OneToMany(mappedBy = "mapType", cascade = CascadeType.ALL, orphanRemoval = true) public List<Child> getChildren() { return children; } I have fairly standard use cases: Must delete children on persist- this works fine. Add new children by adding to collection. This works fine for already persisted parents, but does not work for new parents. EntityManager.merge however does persist the new parent with the new children. Why would adding

JPA @JoinColumn one to many bi-directional relationship with a composite key as FK

自作多情 提交于 2019-12-25 08:23:16
问题 I have been scratching my head over this for weeks now and I have no idea how to work my way around it. I have two tables: Author (author_code, author_number, author_name) author_code and author_number are primary keys Title (author_code, title_code, sequence, title_desc) title_code and sequence are primary keys Code: @Entity @IdClass(AuthorPK.class) @Table(name="Author") public class Author implements Serializable { @Id @Column(name="author_code") private long authorCode; @Id @Column(name=

Taking the difference of temporal fields in JPQL

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:59:05
问题 I have an entity Event which has fields startDate and endDate . I'd like to select only those events that have at most x days left to the their endDate . I want to do this in JPQL and with only one query. How can I do this? 回答1: JPA does not provide any standard date/time functions. You can use a native SQL query using SQL EXTRACT, Or, if you are using EclipseLink you can use the FUNC JPQL operator to call a database specific function, or use EXTRACT if using EclipseLink 2.4, See, http://wiki

'no session or session was closed' with JPA 2 and EJB 3.1

你说的曾经没有我的故事 提交于 2019-12-25 06:49:56
问题 I have stateless session bean with this method: @Override public List<Character> getUserCharacters(int userId) { User user = em.find(User.class, userId); if(user != null) return user.getCharacters(); else return null; } where User class if defined in this way: @Entity @Table(name="Users") public class User implements Serializable{ /** */ private static final long serialVersionUID = 8119486011976039947L; @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) private int id; @ManyToMany(fetch

Put Spring EntityManager in thread for async Servlet 3.0?

牧云@^-^@ 提交于 2019-12-25 06:46:00
问题 We're trying to enable Servlet's 3.0 "async-supported" in our Spring application: Added in web.xml (async-supported)true(/async-supported) for all servlets and filters. Rewrote the request handling code as ** request.getAsyncContext().start(new Runnable() { @Override public void run() { handleRequest(servlet, request, response); } }); ** This causes two problems: Spring Security authentication is lost when running the asynchronous code. There is no EntityManager/session/... any more either.

JPA mapping annotations for Object type

时间秒杀一切 提交于 2019-12-25 02:33:31
问题 I will implement an entity class, something like: @Entity public class XXXEntity { @Id private Long id; private Object entity; } But I am not sure how to map the Object type field? Actually, in my project the object types contain several other entities, like A, B, C. (all A,B, and C implement Serilizable interface) I want to annotate it as @Lob, but I am not sure it is correct? Because Object doesn't implement Serilizable interface. Any ideas about that? Thanks. 回答1: You can not annotate

Add WHERE IN clause to JPA Specification

青春壹個敷衍的年華 提交于 2019-12-25 01:37:40
问题 I'm trying to implement search functionality limited by IN clause: I want to implement search implementation with filter limitation: @GetMapping("find") public Page<MerchantUserDTO> getAllBySpecification( @And({ @Spec(path = "name", spec = LikeIgnoreCase.class), @Spec(path = "login", spec = LikeIgnoreCase.class), @Spec(path = "email", spec = LikeIgnoreCase.class), }) Specification<Users> specification, @SortDefault(sort = "login", direction = Sort.Direction.DESC) Pageable pageable ) { return

Hibernate StaleObjectStateException Issue Calling Merge

风格不统一 提交于 2019-12-25 00:25:34
问题 I'm trying to test optimistic locking using JPA's @Version annotation that I've added to my entity object: @Version @Setter(AccessLevel.NONE) @Column(name = "VERSION") private long version; When I run 2 servers concurrently, I receive a StaleObjectStateException : Exception message is : Object of class [com.myPackage.WorkQueue] with identifier [9074]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or