jpa-2.0

ElementCollection createAlias in hibernate API

六眼飞鱼酱① 提交于 2019-12-04 17:54:25
问题 does anyone know if and how the solution for following question (which is written in the JPA API) can be written using the hibernate criteria API? To be more specific I have a Discussion entity that contains a list of participants (which is a list of usernames): @ElementCollection @Column(name = "user_name") @CollectionTable(name = "DISCUSSION_USER", joinColumns = @JoinColumn(name = "DISCUSSION_ID")) @OrderColumn(name = "ORDER_INDEX") private List<String> participants = new ArrayList<String>(

SpringBoot doesn't handle javax.validation.ConstraintViolationException

我的未来我决定 提交于 2019-12-04 17:52:10
问题 I have defined a pattern for validating email in my Entity class. In my validation exception handler class, I have added handler for ConstraintViolationException. My application utilize SpringBoot 1.4.5. Profile.java @Entity @EntityListeners(AuditingEntityListener.class) @Table(name = "profile") public class Profile extends AuditableEntity { private static final long serialVersionUID = 8744243251433626827L; @Column(name = "email", nullable = true, length = 250) @NotNull @Pattern(regexp = "^([

How to map collection of each subclass from same hierarchy onto one owning class?

十年热恋 提交于 2019-12-04 17:17:38
Does anyone know how to map a collection of each subclass from the same hierarchy onto one owning class, using JPA 2.0 annotations, backed by Hibernate 4.0.0.Final? Bit convoluted, so here's an example. Hierarchy classes look like this: @Entity @Cacheable(true) @Table(name = "hierarcicals") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "class", discriminatorType = DiscriminatorType.STRING) public abstract class MySuperClass { ... @Entity @DiscriminatorValue("SubClassOne") public class SubClassOne extends MySuperClass { ... @ManyToOne(fetch = FetchType.LAZY)

How can I get all @Entity classes from a Persistence Unit?

余生颓废 提交于 2019-12-04 16:48:46
问题 Problem I'm writing a standalone utility program which, given a jar containing a JPA-2 annotated persistence unit, needs to programmatically get a list of all my @Entity classes in a particular persistence unit. I'd like to decide which of 2 approaches would be the way to go to get this information, and why; or if there is another better way I haven't thought of. Solution 1 Java program puts jar on the classpath, creates persistence unit from the classes in the jar using JavaSE methodologies.

Entity must be managed to call remove

元气小坏坏 提交于 2019-12-04 16:42:55
问题 What's going on here? @Stateless @LocalBean public class AppointmentCommentDao { public void delete(long appointmentCommentId) { AppointmentComment ac = em.find(AppointmentComment.class, appointmentCommentId); if (ac != null) { em.merge(ac); em.remove(ac); } } @PersistenceContext private EntityManager em; } On the call to remove I get an IllegalArgumentException with the message being Entity must be managed to call remove: ...., try merging the detached and try the remove again. 回答1: In your

Eager fetch does not seem to join

旧街凉风 提交于 2019-12-04 16:24:49
I'm using play 2.0.4 with Java. I'm trying to save and retrieve a value from the in-memory db that play provides (Ebean is the underlying JPA implementation). Here's some sample code: @NoobDisclaimer ("I'm fairly new to Play and JPA") @Entity public class User extends Model { @Id public Long id; public String name; // Does not fetch eagerly. @ManyToOne(fetch=FetchType.EAGER) private Role role; // Role extends Model { has id and name} public static Finder<Long, User> find = new Finder<Long, User>(Long.class, User.class); public static List<User> all() { List<User> allUsers = find.all(); for

Get rid of if-else ladder when creating JPA criteria query based on sort/filter fields of LazyDataModel

感情迁移 提交于 2019-12-04 16:03:05
I'm using, JPA 2.0 Mojarra 2.1.9 JSF component library, Primefaces 3.5. MySQL 5.6.11 I have a table in MySQL database named state_table with three columns as an example. state_id (BigInt) state_name (Varchar) country_id (BigInt) state_id is a auto-generated primary key and country_id is a foreign key that references a primary key of the country table. This table is mapped by its corresponding entity class named StateTable and the data held by this table are displayed in a Primefaces DataTable , <p:dataTable>...</p:dataTable> . The DataTable column header contains a clickable sort area, <div>

Avoid insert 'null' values to database table via JPA

扶醉桌前 提交于 2019-12-04 15:59:55
问题 im starting with JPA2 and feel quite comfortbale so far. But I have a problem when persisting Entities with null property values for NON NULL database fields with default value. I would like to be able to leave the entity property null and let the database insert the default value. My current setup is openJPA with PostgreSQL. I have this VERSION database table (Vorgabewert = Default value): Spalte | Typ | Attribute ----------------+-----------------------------+----------------------------

Why session bean method throw EjbTransactionRolledbackException when RuntimeException was thrown

别等时光非礼了梦想. 提交于 2019-12-04 13:52:15
问题 I am trying to persist the entity with constraint validation, when invoke persist - there is constraint that thrown and the caller get EjbTransactionRolledbackException ... so I try to call the validation explicit and throw ConstraintViolationException / RuntimeException and still the caller get EjbTransactionRolledbackException ... when I throw MyException extends Exception - the caller get MyException Even when I call explicit sc.setRollBackOnly it's still happened :( This shouldn't be the

JPA relationship not getting updated when children are removed

扶醉桌前 提交于 2019-12-04 13:04:08
问题 Given the following scenario: @Entity public class A { @OneToMany(mappedBy = "a", cascade = CascadeType.ALL) private List<B> bList; } @Entity public class B { @ManyToOne() @JoinColumn(name = "a_id", referencedColumnName = "id") private A a; @ManyToOne() @JoinColumn(name = "c_id", referencedColumnName = "id") private C c; } @Entity public class C { @OneToMany(mappedBy="c", cascade=CascadeType.ALL, orphanRemoval=true) @CascadeOnDelete // eclipselink specific optimization annotation private List