What cache concurrency strategy should be used for @ManyToOne fields for a particular entity class. Would it make sense to use READ_ONLY instead of READ_WRITE, since these fields usually don't change after entity creation
@ManyToOne(fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
...
private User user;
...
Hello,
I have a class mapped as an Entity to persist it in a database. I have an id field as the primary key so every time the object is persisted the value of the id is retrieved from the sequence "myClass_pk_seq", a code like the following one.
@Entity
@Table(name="myObjects")
public class MyClass {
@Id
@GeneratedValue(strate...
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 every...
Hi.
I have problems creating a custom query.
This is what entities:
@Entity
public class ApplicationProcess {
@CollectionOfElements
private Set defaultTemplates;
//more fields
}
And Template.java
@Embeddable
@EqualsAndHashCode(exclude={"used"})
public class Template implements Comparable<Template> {
@Setter priv...
I have an object graph that contains a cycle. How do I get JAXB to handle this? I tried using the @XmlTransient annotation in the child class but the JAXB marshaller still detects the cycle.
@Entity
@XmlRootElement
public class Contact {
@Id
private Long contactId;
@OneToMany(mappedBy = "contact")
private List<Contac...
Title says it all: What is the difference between a UserTransaction and a EntityTransaction?
My rudimentary understanding is that UserTransaction is used when JTA is required (e.g. to do queries on mulitple things), and that EntityTransaction is used when JPA only is required (e.g. when the query is atomic).
Is that the only difference...
I'm looking for an entity detection in OpenJPA. That I don't need to declare all entities in the persistence.xml.
Edit: I'm sorry, I forgot to say that I develop a java se app.
...
I have this class:
public class DBRow {
public String url;
public String title;
public static Hashtable<String, Integer> words;
public Vector<String> keywords;
}
What I must do is store many instances of this class in a database. I'm using Hibernate and JPA to get the job done. Using JPA I've come so far (really not fa...
Hi,
I am using Hibernate Tools to generate the DAO and classes straight from database. There are two tables (table A and B) in the database, and there is a one to many relationship from A to B (multiple rows in B mapped to single A).
In the generated code of A (class A), there is a collection of class B, which reflects the one to many ...
Is there a way to load only selected entities with Hibernate?
I would like to only load a selected handful for integration testing.
...
What's the correct sintax of a JPA insert statement? This might sound like an easy question but I haven't been able to find an answer.
I know how to do it from Java code but I'm looking for a way to insert objects into the database if the database was created.
Any ideas?
...
Hibernate allows you to just say ".id". Let's say I have:
@Entity public class Customer {
@Id private Integer customerId;
@Basic private String customerName;
// getters and setters
}
And I want to get the name of a customer by ID:
SELECT cust.customerName FROM Customer cust WHERE cust.id = :customerId
Notice I put "id" rathe...
Please excuse my long-winded explanation, but I wanted to be as explicit as possible in the hopes of getting as much useful feedback on my situation as possible. You can skip to the questions at the bottom if you are impatient.
Explanation
At my current job, development is done in an antiquated language that is hard-wired to a proprie...
Hi all,
This question is related to "Hibernate using JPA (annotated Entities) and liquibase".
I was actually wondering what to expect when doing a Liquibase diff against a Hibernate mapping definition.
What it seems to produce: A liquibase changelog that migrates the state of my hibernate mappings to the current image of the database....
My webapp contains many entityManagerFactories (DBs) , each has its unique name , such as entityManagerFactoryApp , entityManagerFactoryBusiness , entityManagerFactoryForum ...etc.
In a webapp , I have to add OpenEntityManagerInViewFilter to achieve "Open Session in View" pattern.
<filter>
<filter-name>Spring OpenEntityManagerInVie...
Please tell me, what am I doing wrong.
I have this function:
public String create(){
try {
Iterator<Tag> it = tags.iterator();
List<Tag> tagList = new ArrayList<Tag>();
while(it.hasNext()){
Tag t = it.next();
if (projectsTags.contains(t.getName())) {
...
I am new to Java and JPA. I am trying to connect to a database and return some results from a table, but when I run the query, I get an empty list as a result even though the table has over 100,000 rows.
Here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:...
Is there a way to tell Hibernate to wrap a column in a to_char when using it to join to another table or conversely convert a NUMBER to a VARCHAR? I have a situation where I have a table which contains a generic key column of type VARCHAR which stores the Id of another table which is a Number. I am getting a SQL exception when Hibernate ...
I am trying to execute a query using EclipseLink following the crappy documentation at http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_%28ELUG%29, but every time you need to execute an Expression it uses a variable called "session", but no where does it explain where this "session" variable comes from. I already have a pe...
I'm trying to do a cascading save on a large object graph using JPA. For example (my object graph is a little bigger but close enough):
@Entity
@Table(name="a")
public class A {
private long id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "a")
private Collection<B> bs;
}
@Entity
@Table(name="b")
public class B {
private lo...