jpa-2.0

How do I properly cascade save a one-to-one, bidirectional relationship on primary key in Hibernate 3.6

醉酒当歌 提交于 2019-11-27 06:44:25
I have an one-to-one, bidirectional entity relationship with shared keys. When I attempt to save the owner of the association I get a "null id generated" exception against the owned side of the relationship. I am utilizing hibernate-entitymanager and using spring for transaction management. Owning Entity @Entity @Table(name = "lead") public class Lead { private Long leadId; private LeadAffiliate leadAffiliate; @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getLeadId() { return leadId; } @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn public LeadAffiliate

Failed to lazily initialize a collection, no session or session was closed (despite eagerly fetching)

↘锁芯ラ 提交于 2019-11-27 06:26:17
问题 Okay, I get the above exception in an application I'm working on. I am using JPA and hibernate. Here is the stacktrace: WARNING: #{commissionController.saveCommission}: javax.persistence.PersistenceException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed javax.faces.FacesException: #{commissionController.saveCommission}: javax.persistence.PersistenceException: org.hibernate.LazyInitializationException: failed to lazily

Really dynamic JPA CriteriaBuilder

好久不见. 提交于 2019-11-27 06:10:37
I need to create a "real" dynamic JPA CriteriaBuilder . I get an Map<String, String> with the statements. It looks like: name : John surname : Smith email : email@email.de ...more pairs possible Here is what i implement: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> userRoot = query.from(User.class); query.select(userRoot); List<Predicate> predicates = new ArrayList<Predicate>(); Iterator<String> column = statements.keySet().iterator(); while (column.hasNext()) { // get the pairs String colIndex = column.next(); String colValue

Java EE Architecture - Are DAO's still recommended when using an ORM like JPA 2?

让人想犯罪 __ 提交于 2019-11-27 06:06:46
If I'm using an ORM like JPA2 - where I have my entities that are mapped to my database, should I still be using a DAO? It seems like a lot more overhead. For example, I would need to maintain three extra packages: One that specifies my domain objects (which pretty much map my Entity objects): public class Employee { private String firstName; private String lastName; ... // Getters and setters } One that contains interfaces that specify my DAO methods public interface EmployeeDAO { public void addEmployee(Employee employee); public Employee getEmployeeById(long id); ... } One that contains

How to run an aggregate function like SUM on two columns in JPA and display their results?

穿精又带淫゛_ 提交于 2019-11-27 05:44:22
问题 I am new to JPA. So my question should be so simple to some. Below is the Simple Query in SQL which i would like to convert to JPA. I already have an entity class called TimeEnt . SELECT SUM(TimeEntryActualHours) as UnBilledHrs, SUM (TimeEntryAmount) as UnbilledAmount FROM TimeEnt WHERE MatterID = 200 回答1: The JPA Query Language does support aggregates functions in the SELECT clause like AVG, COUNT, MAX, MIN, SUM and does support multiple select_expressions in the SELECT clause, in which case

SpringPersistenceUnitInfo :: AbstractMethodError

僤鯓⒐⒋嵵緔 提交于 2019-11-27 04:47:24
问题 I have an application using Spring 3.0.5, JPA2 and Hibernate 3.6.7. Maven's handling my dependency management. Here's a pom excerpt: <properties> <spring.version>3.0.5.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> <

javax.persistence.PersistenceException - JPA+Hibernate

扶醉桌前 提交于 2019-11-27 04:40:37
问题 I am new to JPA, when I tried to run the following code, it showing error as " cvc-elt.1: Cannot find the declaration of element 'persistence'. " I cant able to fix this error, could u pls help me out to solve this issue. Cheers Rajesh Persistance.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp

Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'

一笑奈何 提交于 2019-11-27 03:48:50
问题 I would like to store birthdate so I chose date at MySQL, when I create my entities based in my database, it turns out like this: import java.util.Date; // ..code @NotNull(message="fill you birthdate") @Temporal(TemporalType.DATE) private Date birthdate; But when I try to persist it gives me this error: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details. What am I doing

JPA Criteria select all instances with max values in their groups

我怕爱的太早我们不能终老 提交于 2019-11-27 03:36:24
问题 Is there a way to write with JPA 2 CriteriaBuilder the equivalent of the following query? select * from season s1 where end = ( select max(end) from season s2 where s1.contest_id=s2.contest_id ); In JPQL this query is: Select s1 from Season s1 where s1.end = ( select max(s2.end) from Season s2 where s1.contest=s2.contest ) 回答1: This should work, with contest being either a basic Integer property, or a ManyToOne property pointing to another non-basic Entity. EntityManger em; //to be injected

Many to Many hibernate inverse side ignored

▼魔方 西西 提交于 2019-11-27 03:25:35
问题 Hi am reading the hibernate documentation. http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html A many-to-many association is defined logically using the @ManyToMany annotation. You also have to describe the association table and the join conditions using the @JoinTable annotation. If the association is bidirectional, one side has to be the owner and one side has to be the inverse end (ie. it will be ignored when updating the relationship values in the association