jpa

EclipseLink with Spring - Can't persist into Db

I am using Spring + EclipseLink 2 to manage entity on a Derby database. Select object from db works fine but when I try to persist one, nothing happens. Program executes correctly and no exception are thrown. I probably did something wrong, as I'm not familiar with Spring, thanks for your comments and suggestions :) The ServerDaoDb meth...

How to check exist item in cart and update it to 1 if user add it again?

Hello All! i have trouble with JPQL statement, i created NameQuery followed: @NamedQuery(name = "Cart.findExistCart", query = "SELECT c FROM Cart c WHERE c.cartPK.userid = :userid AND c.cartPK.itemid = :itemid "), in stateless bean i create one method to active this query followed: public Cart getUserItemCart(int userid,int itemi...

Best practice to generate a JPA dynamic, typed query?

Hello there, i'm trying to convert a 'TableController'-Class we used (without ORM) to generate dynamic SQL (actually the order column and direction is appended to the SQL). Think of this 'TableController' as a class that have a function to return a list of Entities of a given class (known at runtime), in a given order (String column/pro...

What to put into jta-data-source of persistence.xml?

What value should I place into <jta-data-source> of my persistence.xml? In glassfish admin panel I created a datasource name "abcDS". In my jndi.properties (inside src/test/resources) I defined it like this: [...] abcDS=new://Resource?type=DataSource abcDS.JdbcDriver=org.hsqldb.jdbcDriver abcDS.JdbcUrl=jdbc:hsqldb:mem:testdb abcDS.JtaM...

Why datasource is not found in JNDI after injection from jndi.properties?

This is my persistence.xml: <persistence> <persistence-unit name="MyUnit"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/abcDS</jta-data-source> </persistence-unit> </persistence> This is jndi.properties file from src/test/resources which is supposed to create a datasource during testing...

What is the best way to handle a ConstraintViolationException with EJB3 and entitymanager in an SLSB

here is my code snippet: @Stateless public class mySLSB { @PersistenceContext(unitName = "db") private EntityManager myEntityManager; public void crud(MyEntity myEntity) throws MyException { myEntityManager.merge(myEntity); } } However this merge can cause a ConstraintViolationException, which does not throw MyException (which i...

Usage of @IndexColumn results in a seq_num of 0

I would like to make use @IndexColumn to set seq number of some data the user enters. I am using Spring 2.5.6, JBoss 5.1 (JPA 1.0). For my parent class @Entity @Table(name="material") public class Material implements Serializable { . . /** * List of material attributes associated with the given material */ @OneToMany...

Trouble converting SQL Query into JPQL (Eclipselink)

Hey guys, I have the following query and for the life of me I can't seem to translate it into JPQL. The working SQL is: select * from TB_PRINT_DETAIL y inner join (select JOB_ID,max(COPY_NUM) MAX_COPY_NUM from TB_PRINT_DETAIL group by JOB_ID ) x on y.JOB_ID = x.JOB_ID and y.COPY_NUM = x.MAX_COPY_NUM My feeble attempt at translati...

JPA 2 (EclipseLink) Trying to use UUID as primary key EntityManager.find() always throws exception (Database is PostgreSQL)

I'm trying to use a UUID for a primary key using JPA 2 (EclipseLink). I'm using PostgreSQL as the database. I have my entity declared as follows: I have an Employee table with its PK set as a UUID. I have a JPA Entity mapping to the employee table, which looks like this: @Entity public class Employee { @Id private String id; ...

how to use regular expression in EJB named query

I have query in mysql like SELECT COUNT(DISTINCT MOBILE) FROM TBLM_CUSTOMER WHERE MOBILE NOT REGEXP '^00*0$' AND LENGTH(MOBILE) >= 10; I am using EJB 3.0 and I want to make same query using NamedQuery, same thing is possible using createQuery , but i want to use NamedQuery. Is it possible to use regular expression using NamedQuery in...

Using openSession() over getCurrentSession() - when and why?

This question is in relation to another question I have asked, but what are the reasons as to why you would use openSession() over getCurrentSession()? I know you would use openSession() so that you could self-manage the closing and flushing of the session, however, why would you want to do this manually? I have used openSession() when...

Deleting a member from a ManyToMany collection throws org.h2.jdbc.JdbcBatchUpdateException

public class Group{ @ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, mappedBy="groups") public Set<User> getUsers() { if(users == null) return new HashSet<User>(); else return users; } public void setUsers(Set<User> users) { this.users = users; } } public class User{ public void setGroups(Set<Group> groups)...

JPA QL - "winning bids of a user"

Hi, I have a simple app with User, Bid, and Auction, the relationships are clear I hope. Now I want to implement getWinningAuctionsOfuser( User u ), which would return the auctions which the given user is currently winning. I know how I would do this in SQL, but I don't have much experience with JP-QL. What's the best approach? Curr...