jpa-2.0

JPA @JoinColumn annotation with One To One relationship

浪子不回头ぞ 提交于 2019-12-29 08:56:30
问题 Is it true that @JoinColumn can be used on both side of One to One relationship in JPA ? I was under impression that it should be always used in owning side of One to One relationship as owning side will have foreign key column and this annotation define the attribute of foreign key column . Please clarify if my understanding is not correct . Edit #1 - I wanted to know , In which scenario we will be using @JoinColumn annotation on both side of one to one relationship ? 回答1: The OneToOne

Perform UPDATE without SELECT in eclipselink

不羁岁月 提交于 2019-12-29 06:29:08
问题 Is is possible (without writing custom SQL) to have Eclipselink trust me as to whether to perform an update or insert on a merge, rather than perform a select, then an update or insert? If so, how? In my mind I'd like to use a transient flag and a custom if statement to determine whether the item is already in the database or not, and instruct eclipselink to perform the query required. I understand Hibernate provides this as update() and save() A few notable points: I have a large amount of

Perform UPDATE without SELECT in eclipselink

心不动则不痛 提交于 2019-12-29 06:29:07
问题 Is is possible (without writing custom SQL) to have Eclipselink trust me as to whether to perform an update or insert on a merge, rather than perform a select, then an update or insert? If so, how? In my mind I'd like to use a transient flag and a custom if statement to determine whether the item is already in the database or not, and instruct eclipselink to perform the query required. I understand Hibernate provides this as update() and save() A few notable points: I have a large amount of

Is this possible: JPA/Hibernate query with list property in result?

时光毁灭记忆、已成空白 提交于 2019-12-29 04:18:26
问题 In hibernate I want to run this JPQL / HQL query: select new org.test.userDTO( u.id, u.name, u.securityRoles) FROM User u WHERE u.name = :name userDTO class: public class UserDTO { private Integer id; private String name; private List<SecurityRole> securityRoles; public UserDTO(Integer id, String name, List<SecurityRole> securityRoles) { this.id = id; this.name = name; this.securityRoles = securityRoles; } ...getters and setters... } User Entity: @Entity public class User { @id private

Why should I specify @Column( nullable = false )?

主宰稳场 提交于 2019-12-29 03:32:08
问题 I have an entity annotated with @Entity . If I am responsible for creating the CREATE TABLE scripts why should I specify @Column( nullable = false ) when I can create a column in the database with the NOT NULL keywords? Is there any example that shows the benefits of using this property in a field? 回答1: Better error messages and error handling, especially if you also add the JSR303 @NotNull annotation. If you create the column as NOT NULL but don't tell JPA it's not null, JPA will assume that

Filter do not initialize EntityManager

烈酒焚心 提交于 2019-12-28 18:44:07
问题 I trying to use the Open Session in View pattern, but everytime I try to catch the EntityManager in my ManagedBean the entityManager come NULL here is how I'm doing: package filters; // imports.. public class JPAFilter implements Filter { private EntityManagerFactory factory; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { EntityManager entityManager = this.factory.createEntityManager(); request

JPA 2 Criteria Fetch Path Navigation

自作多情 提交于 2019-12-28 11:54:24
问题 With JPA 2 Criteria Join method I can do the following: //Join Example (default inner join) int age = 25; CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Team> c = cb.createQuery(Team.class); Root<Team> t = c.from(Team.class); Join<Team, Player> p = t.join(Team_.players); c.select(t).where(cb.equal(p.get(Player_.age), age)); TypedQuery<Team> q = entityManager.createQuery(c); List<Team> result = q.getResultList(); How can I do the same with fetch method, I expected that

Application managed JPA, when is Transaction needed

让人想犯罪 __ 提交于 2019-12-28 06:34:17
问题 We are working on a little web (will run on Tomcat) with the data layer done with JPA (Eclipselink). I did similar thing some time ago. But i were always unsure when i need to begin and end transactions or do a flush. At the moment i use transaction if i add (persist) and remove objects. If i call setters on an already persisted object i do not use transactions. Is there a guide/ tutorial or a short answer when to use transactions or how to implement application managed JPA correctly. 回答1: I

Hibernate triggering constraint violations using orphanRemoval

左心房为你撑大大i 提交于 2019-12-28 02:52:07
问题 I'm having trouble with a JPA/Hibernate (3.5.3) setup, where I have an entity, an "Account" class, which has a list of child entities, "Contact" instances. I'm trying to be able to add/remove instances of Contact into a List<Contact> property of Account. Adding a new instance into the set and calling saveOrUpdate(account) persists everything lovely. If I then choose to remove the contact from the list and again call saveOrUpdate, the SQL Hibernate seems to produce involves setting the account

Adding entity doesn't refresh parent's collection

半世苍凉 提交于 2019-12-25 18:24:57
问题 the question and problem is pretty simple, though annoying and I am looking for a global solution, because it's application-wide problem for us. The code below is really not interesting but I post it for clarification! We use PostgreSQL database with JPA 2.0 and we generated all the facades and entities, of course we did some editing but not much really. The problem is that every entity contains a Collection of its children, which however (for us only?) is NOT updated after creation a