jpa

issue with updating record in database using JPA

I have object in database with values as follows: id =1 name = "john" chargeid = 6 I am using merge statemet to update the code em.merge(obj) When i see the query generated by JPA i found that in update query only fields which has new or not null values are updated. I checked the bean which is associated with this object and found th...

setting values of some fields to null using JPA

In jpa merge, are all coumns of updated or only the columns which has new values? While updating if i set value of some attribute to null, will null value will be stored in that cloumn in db, or will it retain previous value? ...

best approach for updation using JPA

Using JPA which method should I follow while updating? approach 1 obj o = new obj() o.setName('val') set other values entitymanger.merge(ibj) approach 2 obj o = getObjFromDb(obj) obj.setval(name) //not am not updating other attributes entitymanage.merge(obj) ...

JPA query exception

Hello ! I have a query builded with EntityManager: Query q = em .createQuery("SELECT * FROM :table WHERE username = :username AND password = MD5(:password)") .setParameter("table", User.class.getName()) .setParameter("username", txtLogin.getText()) .setParameter("password", passPassword.getPassword()) ; User user = (Us...

Wicket+Spring+JPA+Hibernate: No Persistence Unit Found

Hi! I'm developing a web application using Wicket+Spring+JPA+Hibernate. This is my first project with this setup and I think I've probably made some mistakes. I get the following error: No persistence unit called "ApplicationEntityManager" found. My persistence.xml file looks like this: <?xml version="1.0" encoding="UTF-8"?> <persiste...

jpa/hibernate drag-n-drop/orm/graphical relations

Hey all, I'm reviewing the IntelliJ ability related to JPA ER Diagrams (http://www.jetbrains.com/idea/features/jpa_hibernate.html), and is something I've been looking for a while. Does anyone know of other tools that have similar abilities, whether as standalone, eclipse plugin, or other alternatives with the intent that the Graphical T...

Hibernate two tables and one object

Hello, I have this situtation: Table1: tab_id field11 field12 Table2 id tab_id field21 field22 I have to create one object on this two tables for example: object: @Id tabId @Colummn(name="field11") field11 @Colummn(name="field12") field12 @Colummn(name="field21") field21 When i update field21 table2 should update this f...

JPA: question about merging an entity before removing it.

I know I have to merge the entity before removing it, but I never thought I have to do it inside EJB. First I have these: e = (Event) scholarBean.merge(e); scholarBean.remove(e); in my managed bean. It give me this error java.lang.IllegalArgumentException: Entity must be managed to call remove: com.scholar.entity.Event@998, try mergi...

How to set collection items for in-clause in jpql?

Is there a possiblity in JPA 2.0 to set a collection for in-clause in jpql-query? (I'm using EclipseLink) The next example fails: TypedQuery<Person> q = em.createQuery("select p from Person p where p.name in (?1)", Person.class); List<String> names = Arrays.asList(new String[] { "Bill Gates", "Steve Jobs" }); // THIS FAILS q.setParame...

Change Table Name of an Entity on runtime?

There is this is this table that is being generated on a monthly basis. Basically the table structure of all monthly tables is the same. Since it would be a lot of work to map the same entity just with a different table name, Is it possible to change the table name of an entity as follows on runtime since they have the same table struc...

JPA/Metamodel: Strange (inconsistent ?) example in Sun Docs

In Sun Online resources, they provide son example about the usage of the Criteria/Metamodel API, but as far as I understand Java, it seems to be impossible to work: CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> Pet_ = m.entity(Pet.class); EntityType<Owner> Owner_ = m.entity(Owner.cla...

What transaction manager to use? (JPA, Spring)

Hi! I'm developing a web application based on JPA + Hibernate, Spring and Wicket. I was wondering what's the best way of implementing transactions in my code? What transaction manager should I use? Should it be org.springframework.orm.jpa.JpaTransactionManager, or org.springframework.jdbc.datasource.DataSourceTransactionManager or someth...

JPA and DAO - what's the standard approach?

I'm developing my first app with JPA/Hibernate and Spring. My first attempt at a DAO class looks like this: @Repository(value = "userDao") public class UserDaoJpa implements UserDao { @PersistenceContext private EntityManager em; public User getUser(Long id) { return em.find(User.class, id); } public List g...

DAO and Service layers (JPA/Hibernate + Spring)

I'm designing a new app based on JPA/Hibernate, Spring and Wicket. The distinction between the DAO and Service layers isn't that clear to me though. According to Wikipedia, DAO is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing...

Extract the primary key from a entity object in JPA 2.0?

Let's say we have an entity object. Is there a way to extract a primary key from it? I want to do something like this: public static Object extractPrimaryKey(EntityManager em, Object obj) { return em.giveMeThePrimaryKeyOfThisEntityObject(obj); } Reason for that is to get an attached copy of detached entity: public static Object ...

How to map a Map<String,Double>

I tried @ManyToMany(cascade = CascadeType.ALL) Map<String, Double> data = new HashMap<String, Double>(); but it produces the error : org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.company.Klass.data[java.lang.Double] at org.hibernate.cfg.annotations.CollectionBinder.bindManyTo...

Multiple JPA persistence units pointing to same database?

Can we have more than one JPA persistence units pointing to same database, in different Java projects and deployed on the server at the same time? By same time I mean, not deployed at the same second but deployed together. I am using a hsqldb database. I am having a client-server model for my project. I have one single unified database ...

Scala, JPA & nullable fields

In trying to use Scala with JPA, I have the following snippet as part of the definition of an entity @Column(name = "ACC_INT", nullable = true) @BeanProperty var accInt: Double = _ All is fine until I retrieve some data and I get the following exception: org.springframework.orm.hibernate3.HibernateSystemException: Null value was as...

Single DAO & generic CRUD methods (JPA/Hibernate + Spring)

Following my previous question, DAO and Service layers (JPA/Hibernate + Spring), I decided to use just a single DAO for my data layer (at least at the beginning) in an application using JPA/Hibernate, Spring and Wicket. The use of generic CRUD methods was proposed, but I'm not very sure how to implement this using JPA. Could you please g...

HSQLDB is eating all my memory

Hi all, I'm using a HSQLDB for an application that stores research data and there is quite a lot of data. HSQLDB insists on always loading the tables into memory. I've tried fixing this by setting hsqldb.default_table_type=cached in my persistence.xml but that does not work. Is this the wrong place? persistence.xml <persistence-unit ...