jpa

HIbernate+JPA Composite Key problem: generating select sql with wrong columns

Here is my sample codes. PrimaryKey Class: public class ReplAreaElemDataCompositeKey implements Serializable{ private static final long serialVersionUID = 1L; private int imageElementID; private int variableID; public ReplAreaElemDataCompositeKey() { super(); } /** * @param imageElementID * @param variableID */ public Re...

Composite Foreign Key lost in merge() operation (JPA/Hibernate)

Imagine an Employee Entity that references a Department using a Compound Key: @Entity public class Employee { ... @ManyToOne @JoinColumns({ @JoinColumn(name="dept_country", referencedColumnName="country"), @JoinColumn(name="dept_id", referencedColumnName="id") }) private Department dept; ... In a Stateles...

JPA / OpenJPA Same value in all rows

I have a problem with OpenJPA I try to read all rows from a table but the primary key has always a same value(value = 0)!?!?!? for (Object o : em.createQuery("select x from AnnouncementsEntry x") .getResultList()) { //alway returns "0" in every row long id = ((AnnouncementsEntry) o).getEntryI...

Openjpa maven plugin error

Update 3: Addes following code to the pom so openjpa could find the persistence.xml file. Got some query errors left but I finally got openjpa to work :). <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> Update2: Set up maven p...

How to create Id on hibernate entity that is a byte[] that maps to a varbinary value in mysql

I am trying to create an Entity that has a byte[12] id in hibernate. It seems like it does not like to have a byte[] as a primary key and as another column it sets it up as a tinyblob in the backing mysql db. I have tried to create a String, but the problem is that the string in java is 2 bytes per char, while it is one byte per char i...

JPA best practice question - Updating one field only

My question is similar to http://stackoverflow.com/questions/3476613/updating-one-field-in-jpa-entity Basically I have an entity Foo which has some basic fields (enum, String, DateTime) and it has two other fields. One of them is a OneToOne and the other is a OneToMany implemented using a Collection. I have two threads which are run...

JPA Query toString

Hello SO, I have a JPA Query I am executing on the Google App-Engine datastore. I am building the query using parameters. After all parameters have been inputted, I wish to view the Query String. That is, I wish to view the actual query being executed by the datastore. Is that even possible? It would really help me in debugging. To SOL...

How to properly implement a domain object with composite id in Hibernate?

I have the following domain objects: public class Department { private long departmentId; } public class Manager { private long managerId; } public class Project { private ProjectId compositeId; @ManyToOne private Department department; @ManyToOne private Manager manager; } public class ProjectId...

JPA entity joining issues (i think)

Hi all, Im learing JPA and having problems, im using entity generation stuff(too tired, cant think of the name) in my persistance file so my entitys are upto scratch. But im having problems joining them. my problem is that i dont think im joining the entitys properly Exception javax.servlet.ServletException: java.lang.reflect.Invoca...

Howto implement Spring Security User/Authorities with Hibernate/JPA2?

I am trying to implement DAOs to work with Spring Security database authentication in Hibernate/JPA2. Spring uses following relations and associations in order to represent user & roles: repesented as postgresql create query: CREATE TABLE users ( username character varying(50) NOT NULL, "password" character varying(50) NOT NULL, ...

How do I change this query to make it return records that meet the `minPrice` condition even if the `keywords` value is null?

I don't know if this is a problem that is specific to Google App Engine for Java, but if the value set as the keywords parameter is a null String, then nothing is returned from the query, even if a minPrice is set. How do I change this query to make it return records that meet the minPrice condition even if the keywords value is null? ...

javax.persistence.PersistenceException: Transaction failed to flush

I got the JPA exception "javax.persistence.PersistenceException: Transaction failed to flush" Then I deleted my local datastore(datastore-indexes-auto.xml and local_db.bin) from my system. Recreated all the data again and after that, the exception was gone. I want to know what did just happened ? The following is the stacktrace...

hyperjaxb3 xsd:string length in JPA entity

Hi guys, I use Hyperjaxb3 to generate JPA entities from XSD schema. I have a xsd:string type that I want to use for description text (text area in the UI): <xsd:complexType name="Description"> <xsd:simpleContent> <xsd:extension base="**xsd:string**"> <xsd:attribute name="abc" type="xsd:NCName" use="optional" /> ...

Can I define relationships in an Entity class without having them in the database?

Hi, I have to write an application in Java EE6. I have been given a MySQL database, to which I am not allowed to make any changes. The database is well structured and normalized, but does not have any foreign keys defined to enforce integrity. (It uses the MyISAM engine). Is it possible to define relationships (using @JoinColumn, @Many...

ejb3: mapping many-to-many relationship jointable with a simple primary key

often in books, i see that when a many-to-many relationship is translated to a DB schema, the JoinTable gets a compound key consisting of the primary keys of the tables involved in many-to-many relationship. I try to avoid compound keys completely. So i usually create a surrogate key even for the JoinTable and allow the database to fill ...

Oracle CLOB and JPA/Hibernate ORDER BY?

I have a JPQL query that works fine with MySQL and SQL Server. But with Oracle it fails with ORA-00932: inconsistent datatypes: expected - got CLOB. The reason seems to be that Oracle does not support ORDER BY with CLOB columns. Is there any JPQL work around for this? ...

Using stateless EJB beans in an Entity Bean

Obviously using stateless EJB beans in an entity bean smells, but please consider a scenario as follows and tell me if you know of a better solution: I have an InvoiceTemplate Entity Bean with field NextInvoiceDate Generating NextInvoiceDate is a complex procedure and should be performed outside of the InvoiceTemplate class NextInvoice...

JPA or Hibernates With Oracle Table Partitions?

Hi, I need to use an Entity framework with my application, and I have used table - partitions in Oracle database. With simple JDBC, I am able to select data from a specific partition. But I don't know whether I can do the same with hibernate or Eclipse link (JPA). If someone knows how to do that, please do let me know. usually the sel...

Rollback on every checked exception, whenever I say @Transactional

Since the programmer is forced to catch all checked exception, I to throw checked exception in case of any problem. I would like to rollback on any of those expections. Writing rollbackFor=Exception.classon every @Transactional annotation is very error-prone, so I would like to tell spring, that: "whenever I write @Transactional, I mean ...

Eclipse does not recognize content of persistence.xml

Im getting the following error in eclipse: The persistence.xml file does not have recognized content. My persistence.xml file works great in my application but eclipse keeps giving me this error. I got this after moving the file and updating my project configuration with m2eclipse. I did not change the file itself. Anyone knows how to...