I'd like to have a @Unique constraint with Bean Validation, but that is not provided by the standard. If I would use JPA's @UniqueConstraint I wouldn't have a unique validation and error reporting mechanism.
Is there a way to define @Unique as a Bean Validation constraint and combine it with JPA, such that JPA creates a column with an u...
Even though I set the attribute to be @Column(unique=true), I still insert a duplicate entry.
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(unique=true )
private String name;
...
}
I set the name using regular EL in JSF. I did not create table ...
Hi,
We have implemented JUnit4 in our application which uses Spring core & JPA with DB2.
We need to test a full functionality which retrieves data from one database and merges into another database.
Test case for retrieving the data from 1st database is written and it is running without any error perfectly but the records are not st...
I have a field with an unique constraint:
@Column(unique=true)
private String uriTitle;
When I try to save two entities with the same value, I get an exception - but another exception than I exected:
java.lang.IllegalStateException: <|Exception Description: No transaction is currently active
at org.eclipse.persistence.interna...
When a unique constraint is violated, a javax.persistence.RollbackException is thrown. But there could be multiple reasons to throw a RollbackException. How can I find out that a unique constraint was violated?
try {
repository.save(article);
}
catch(javax.persistence.RollbackException e) {
// how to find out the reason for the ...
Hi there,
I've got two entities
ServiceDownload.java
@Entity
public class ServiceDownload implements Serializable {
private static final long serialVersionUID = -5336424090042137820L;
@Id
@GeneratedValue
private Long id;
@Length(max = 255)
private String description;
private byte[] download;
private String fileName;
@ManyToOne...
I have a problem with entity versioning. Here's what I want to archive:
Let's say that I have entity class A (POJO with javax.persistance.* annotations). It's in relations with other entities. Then I need to insert new version of A. All rows should still reffer to old one, but it should be marked as archived and new version should be in...
I am trying to establish a relationship between 2 entities which would be zero-to-one. That is, the Parent can be saved without the associated Child entity and also along with the assoicated Child.
Following are the 2 Entity classes...
Employee (Parent)
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUT...
Hi there,
I've got some byte[] fields in my entities, e.g.:
@Entity
public class ServicePicture implements Serializable {
private static final long serialVersionUID = 2877629751219730559L;
// seam-gen attributes (you should probably edit these)
@Id
@GeneratedValue
private Long id;
private String description;
...
I am using Hibernate entity manager 3.5.1-Final with MS SQL Server 2005 and trying to persist multiple new entities. My entity is annotationally configured thus:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
After calling
entityManager.persist(newEntity)
I do not see the generatedId set, it remains as 0. ...
I have a @ManyToMany relationship between two entities. When I perform an update on the owning side, it appears that JPA deletes all the linked records from my database and re-inserts them. For me this is a problem because I have a MySQL trigger that fires before a record is deleted. Any ideas on how to get around this problem?
Thanks R...
I want to make sure that all rows in my table have a unique combination of two fields, and I want to specify this using annotations in my entity class. I have tried using a combination of @Table and @UniqueConstraint but apparently I'm doing it wrong, in that I can only seem to specify that the separate columns should be unique (I can a...
I am working on a project that is in transition from proof-of-concept to something worthy of a pilot project. One of the key improvements for this phase of development is to move away from the current "persistence" mechanism, which uses a hash table held in memory and periodically dumped to a file, to a more traditional database back-end...
I'm currently stuck with what seems to be a very simple problem, but I just can't seem to find a way around:
I have 2 identical tables:
tbl_creditcard_approved_txns
tbl_creditcard_declined_txns
The fields in both are identical, and I have one class - Transaction that is used to represent all the appropriate fields in the tab...
Let's say we have:
@Entity public class Order {
@Id private int id;
@OneToMany(mappedBy="order") private List<Item> items;
...
}
and
@Entity public class Item {
@Id private int id;
@ManyToOne private Order order;
...
}
And let's say there is 10.000 orders with each having 20 items.
We need to iterate thought all order...
Hi everybody,
I read this article on the maven project web page that lists the different directory layouts (like: src/main/resources which is for Application/Library resources).
The problem is that when I run the following command (found here):
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactI...
I am not sure what the most appropriate way to handle JPA objects that are shared using a JAR file to multiple projects. ie If you have multiple projects that all have an Employee and Contact and Address objects, and you want to put them in a JAR file, how does this work. ie
Employee.jar
jpa/EMF.class
jpa/Employee.class
jpa/Co...
What is the correct way to write this JPA query? I am just guessing as I cant work it out or find it in my JPA book.
Query query=em.createQuery("select m from Meeting m where count(m.attendees) = 0");
return query.getResultList();
I am currently trying this with Hibernate and I get a mysql error!
ERROR org.hibernate.util.JDBCExceptio...
I have 4 persistent classes which all have the same fields (exactly) the only 3 difference between them is 1) the class name, 2) the table name and 3) the data. i am aware that this might seem strange to some but trust me there is a good reason which i won't go into here.
now, i'm using hibernate annotations to configure my class which ...
i have a method inside service layer that is called by view layer to save content. the model is annotated with @Version JPA so support concurrent-update. but during web application peak-usage, sometime, i will get
17 Aug 2010 16:30:26,477 ERROR [http-2020-23] - Could not synchronize database state with session
org.hibernate.StaleObjec...