We have a simple data model reflecting the following...
User contains many @OneToMany addresses
User contains many @OneToMany phones
User contains many @OneToMany emails
User belongs to a @Organization via @ManyToOne
We would like the customers to capture all user information in a excel / csv sheet and provide it to our upload tool. ...
Could someone please explain to me what the main differences are between JPA and Hibernate?
Where to use Hibernate ?
Where to use JPA?
Why not entity bean?
...
My persistence.xml is located in A.jar and entity classes are in B.jar. When trying to create a query using entity manager (from A.jar), I got exception saying it cannot find NamedQueries. However, named queries are listed on the entity class using annotation.
Tried to use <jar-file/> to include B.jar in persistence.xml, but it doesn't ...
I've seen (and done) data source configuration in two ways (the code below is just for demo):
1) configuration inside persistence units, like:
<persistence-unit name="LocalDB" transaction-type="RESOURCE_LOCAL">
<class>domain.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<proper...
I have build my data model using JPA and am using Hibernate's EntityManager 3 to access the data. I used HSQLDB for testing (junit). I am using this configuration for other classes and have had no problems.
However, the latest batch of tables use a composite-key as the primary-key and I am not able to retrieve the populated row from...
I am using Java EE 6. Just want to throw it out there first
Here is the relationship. A customer can have multiple facility
Here is Customer Class
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToMany(cascade=CascadeType.ALL)
@Jo...
About to kill myself here.
This is failing:
List<String> names = new ArrayList<String>();
names.add("sold");
Query query = em.createQuery("FROM PropField propField WHERE propField.name IN (?)");
query.setParameter(1, names);
List<PropField> fields = query.getResultList();
And so is this:
List<String> names = new ArrayList<String>();...
I have a java web app running under Spring 2.5.6, Hibernate 3.4 (with Hibernate as the JPA provider), and Tomcat 6. I have it working with one DB schema / persistence unit but now need to connect to 2 schemas / persistence units. Can I do this without moving to a J2EE container such as JBoss or Glassfish? Will I need to use something lik...
I've used eclipselink in a web project in netbeans. Works nice and easy. How can I do the same in a project unrelated to web(console app)?
In my web app I have:
@PersistenceUnit
EntityManagerFactory enf;
Which instantiates enf. This does not work in A console app.
...
My problem is that I have an object A which contains a list of B Objects
@Entity
class A {
@OneToMany(cascade={CascadeType.MERGE})
List<B> list;
}
When I make a "merge" of an object A and then call "flush" inside a stateless EJB method
em.merge(a); //a is of class A
em.flush(); //doesn't flush "list"
it actually doesn't wor...
I installed Eclipse Helios with the m2eclipse maven plugin.
I want to create an application using JPA. So, what I do is: New > Maven Project then I select the maven default archetype.
The problem is that I want to add the "org.eclipse.persistence" dependency that I can't find.
Where is it? Can we add it manually? Should I update a sort...
I have four entities that are involved in a query that I'm having a little trouble with. The relationship is as follows : Exchange----*Contract*----*Combo----*Trade and the (simplified) entities are as follows:
@Entity
public class Exchange implements Serializable {
@Id(name="EXCHANGE_ID")
private long exchangeId;
@Column
...
Hi guys I am new to Hibernate and JPA
I wrote some functions, initially, I set fetch = FetchType.LAZY in the entity class.
But it gave me error:
"org.hibernate.LazyInitializationException: could not initialize proxy - no Session"
@OneToMany(cascade = CascadeType.ALL, mappedBy = "logins", fetch=FetchType.LAZY,targetEntity=Invoice.clas...
I have a list of IDs in a String, and want to use Hibernate to get the rows with these IDs. TrackedItem is a Hibernate/JPA entity (sorry if I'm getting the naming mixed up here).
My code is:
String idsText = "380, 382, 386";
ArrayList<Long> ids = new ArrayList<Long>();
for (String i : idsText.split(","))
{
ids.add(Long.getLong(i))...
i have a java bean , now i want to be sure that the field sholud be unique.
Am using following code
@UniqueConstraint(columnNames={"username"})
public String username;
But am geting some error.
@UniqueConstraint is dissallowed for this location
Whats the proper way to use unique constraint?
Note:I am using play framework
...
My DAO integration tests are failing because entities created during the tests are still in the database at the start of the next test. The exact same behavior is seen from both MySQL 5 and H2.
The test classes are annotated with:
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/testPersist-application...
I have a problem with updating related entities.
Let me start with a straightforward example.
Suppose I have a User 1:1 Profile relation.
How can I update (replace) Profile entity which belongs to User ?
I have tried the followings without success (both OneToOne relation has CascadeType=ALL property)
em.getTransaction().begin();
1.U...
I'm reading Pro JPA 2. The book talks begins by talking about ORM in the first few pages.
It talks about mapping a single Java class named Employee with the following instance variables - id,name,startDate, salary.
It then goes on to the issue of how this class can be represented in a relational database and suggests the following sch...
Hi All,
I use EJB3 container managed persistence i.e an EntityManager is injected via @PersistenceContext annotation. The persistent context then may be propagated to nested EJBs. Transactions are also managed by the contaner (glassfish).
Usually I would drop persistence.xml into META-INF directory and the container would work out whic...
If I have something like this
@Entity
public class Facility {
...
@ManyToOne
@JoinColumn(name="CUSTOMER_FK")
private Customer customer;
...
}
does my @NameQuery like this
@NamedQuery(name="Facility.findByCustomerId", query="select c from Facility c where c.customer=:customer_fk")
or like this
@NamedQuery(name="...