jpa

Can spring transactions unsynchronize a synchronized method?

My colleague and I have a web application that uses Spring 3.0.0 and JPA (hibernate 3.5.0-Beta2) on Tomcat inside MyEclipse. One of the data structures is a tree. Just for fun, we tried stress-testing the "insert node" operation with JMeter, and found a concurrency problem. Hibernate reports finding two entities with the same private key...

JPA Query Validating if input exist in database

Hi, I want to validate if input exist in database in netbeans IDE protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Transaction1 t = new Transaction1(); //t.setTransactionID(12345); t.setFromAccNo(Integer....

Trouble creating unique table of Strings when persisting List<String>

Suppose I have an entity: @Entity public class AnEntity implements Serializable{ @ElementCollection private List<String> strings = new Vector<String>(); // other stuff } I am using EclipseLink(JPA 2.0). The strings in this List may have the same values in many AnEntity objects. That is to say, many AnEntity objects may referen...

How do I represent this using JPA ?

Hi, I would like a 'RolesPlayed' entity with the following columns user role department/project/group All the three columns above constitute a composite primary key. I would like to know if defining a column to be one of department/project/group possible ? If yes, how ? Or do I need to break the entity into DepartmentRoles, GroupR...

Can a @OneToOne relationship contain a @ForiegnKey annotation

Does it make sense to have a @OneToOne member contain a @ForiegnKey annotation. @Entity class User { @Id @GeneratedValue(strategy = IDENTITY) int id; @OneToOne @ForeignKey @JoinColumn(name = "home_address_id", referencedColumnName = "id") Address homeAddress; } @Entity class Address { @Id @Generat...

Value in db is a hyperlink, and wish to list based on the value of the hyperlink

Hi, I have made my parameter as a hyperlink. Now i want to click the hyperlink and then list of all information of that value in hyperlink. How do i do that? From Account No | To Acc No | Amount | Date So, from account no is value exist from db, and a hyperlink. so i wanna click from accno e.g (123456), and then it will list all tran...

GraniteDS on GAE datastore JPA - Key class problem

I'm using GraniteDS(2.1.0RC2) on GAE with JPA annotiations. I have following class on flex side: [Bindable] [RemoteClass(alias="models.User")] public class User { public var key :String; public var login :String; } and on java side: @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) priv...

How to do regular database cleanup in a JPA application?

Short background: I have a software that regularly downloads files. The Statistics of these downloads are stored in the database as a DownloadResult entity, which is in turn associated to the entity representing the download job. Now I want to make sure, that only a fixed number of the n latest downloads are preserved in the database. A...

Entities cannot be cast to java.lang.Double

public static List<Transaction1> debitSourceAccBalance (Integer youraccinput, Integer toaccinput, String recname, Double amtsender) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Query q = em.createQuery("SELECT t from Transaction1 t where t.fromAccNo =:youraccinput AND t.toAccNo =:toaccinput A...

Class file not found in IntelliJ

In IntelliJ I get this weird error when I try to compile. Cannot find annotation method 'cascade()' in type 'javax.persistence.ManyToOne': class file for javax.persistence.ManyToOne not found I know, it seems pretty obvious what the problem is, but having spent too much time on this problem I now turn my trust to you! I use ideaCommu...

EntityManagerFactory error on Websphere

I have a very weird problem. Have an application using Hibernate and spring.I have an entitymanger defined which uses a JNDI lookup .It looks something like this <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <propert...

org.hibernate.propertyvalueexception not-null property references a null

Hi, im new to JPA, i got the error above when trying to persist the transaction data. Here's my Entity: @Entity @Table(name = "transaction1") @NamedQueries({ @NamedQuery(name = "Transaction1.findAll", query = "SELECT t FROM Transaction1 t"), @NamedQuery(name = "Transaction1.findByTransactionID", query = "SELECT t FROM Transac...

Spring+JPA+Hibernate: persist is updating the entity surprisingly. Please go through the details.

Hi, In my code, I did as follows: queried for a course entity populate it with the given course data. courseDao.update(entity) which internally calls persist(entity) method. Surprisingly, the data is got updated successfully. I am confused with this behaviour of persist method. Please help me out. code is as below: //My Service....

Best Practices for Building Where-In Clause in EclipseLink 1.1

I'm on a project using EclipseLink 1.1, and I have a query where the obvious thing for me to do is use a Where-In clause, like so: List<String> things = populateListOfThings(); String queryString = " select s from Stuff s where s.thing in (:things) "; Query query = em.createQuery(queryString); query.setParamete...

Keep all entities in one ejb module

There are few applications that use java persistence. Each application has its own set of entities that represents the same tables in DB. For instance, application A has entities for Table1, Table2, etc; at the same time, application B also has entities for Table1, Table2, etc. Instead of that I want to create a new EJB module with 1 b...

exception in Persistence query

I'm trying to retrieve a table using persistence framework the code i have written is in simple java class file in webapplication the code in the java class EntityManager em = null; EntityManagerFactory emf = null; public List fname (String id) { String fname = null; List persons = null; try { emf = Persistenc...

Typesafe Primary Key in Hibernate/JPA

I am looking for a way to have a typesafe primary key for my entities using generics in Hibernate. Instead of doing this @Entity public class User{ @PrimaryKey Long id } I was thinking of doing this... @Entity public class User{ @PrimaryKey PrimaryKey<User,Long> id } Or take the type inference even further... Any ideas? Has ...

EJB3 - @Column(insertable="false") question

Hi All, I'm building a J2SE application with EJB3 and an Oracle Express Edition DB. My problem is like that - I set an EntityBean in my project which matches a table in the DB. The table contains a column which is not nullable and has a default value. All I want is that when persisting a new data to this table using the EJB, the column...

How should one handle a javax.persistence.OptimisticLockException ?

I'm new to JPA so forgive me if not being clear. Basically I want to prevent concurrent modifications by using Optimistic Locking. I've added the @Version attribute to my entity class. I need to know if this algorithm on handling OptimisticLockException is sound. I'm going to use the Execute Around Idiom like so: interface UpdateUnitO...

JPA Native Query to tables from different schema in Oracle

I have table MV_ULICE in schema ADRESY. However in JPA I connect to database (Oracle) using different user then ADRESY. This user has privilege to access tables from schema ADRESY, so in JPA there was no problem with defining entities, since you can easily provide different schema in entity definition: @Entity @Table(name = "MV_ULICE", ...