jpa-2.0

JPA Entity for Drop Down columns

非 Y 不嫁゛ 提交于 2019-12-07 21:09:58
问题 I am using JPA 2.0 with Hibernate 4.1.0, I have the following in my Entity class @Entity @Table(name = "PRODUCTS") public class Product { private String productNo; private String productDesc; private Date deliveryDate; private Date invoiceDate; private Integer productCurrencyId; private String productCurrency; The above will be used in application for displaying records as well as for CRUD operation. From the above productCurrencyId and productCurrency will be used in the application for drop

JPA - Removing of elements of a bidirectional Relationship

半城伤御伤魂 提交于 2019-12-07 20:26:58
问题 Why can i remove elements of a bidirectional relation although only one side of the relation is managed in persistence context (Example I)? When i have an unidirectional Relationship that doesn't work (see Example II). Why? Entities: @Entity Class User { ... @OneToMany(mappedBy = "user") private List<Process> processes; @OneToOne // Unidirectional private C c; ... @PreRemove private void preRemove() { for (Process p : processes) { p.internalSetUser(null); } } ... } @Entity Class Process { ...

Learning resource for Configuring Hibernate JPA 2.0 on Glassfish server

泄露秘密 提交于 2019-12-07 15:44:53
问题 I am trying to create a new Java EE project using hibernate and JPA 2.0 on the glass fish server. Can you guys provide me some resources to configure the above so that they work seamlessly? I have tried using netbeans and generated the persistence unit by using the hibernate provider, but I end up getting this error: javax.persistence.PersistenceException: [PersistenceUnit: DBAppPU] Unable to build EntityManagerFactory 回答1: First, install Hibernate support via the update tool (or follow the

Hibernate JPQL CURRENT_DATE not working on SQL Server

风流意气都作罢 提交于 2019-12-07 15:20:30
问题 I have the following JPQL query: SELECT x FROM Bla x WHERE x.deadline < CURRENT_DATE This works as expected on MySQL. But SQL Server complains that CURRENT_DATE is not recognized. I am asking myself what exactly the problem is. Then CURRENT_DATE is a standard JPA function that should resolve independent from the underlying RDBMS. Further the Hibernate documentation also has CURRENT_DATE documented (see here: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch11.html#ql-expressions)

AbstractMethodError when creating typed query with Hibernate 3.6.3 and JPA 2.0

自闭症网瘾萝莉.ら 提交于 2019-12-07 13:13:56
问题 I'm using Hibernate and JPA for a small project. Somehow when trying to obtain an typed Query, the java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerImpl.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery is thrown; org.hibernate.ejb.EntityManagerImpl is from hibernate-entitymanager-3.3.2.GA.jar . This is not okay throwing the above exception: public Account read(Account entity) { EntityManager em = ManagedEntityManagerFactory.getEntityManager(); String

Cascade deleting from join table with @ManyToMany annotation

筅森魡賤 提交于 2019-12-07 12:14:53
问题 Hi I got a problem with mapping my entities. I'm using JPA2 and Hibernate implementation. I got tables with @ManyToMany annotation http://img204.imageshack.us/img204/7558/przykladd.png I mapped it with : @Entity @Table("employee") class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column private String name; @ManyToMany @JoinTable(name = "proj_emp", joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "id"), inverseJoinColumns =

Disabling EclipseLink cache

余生长醉 提交于 2019-12-07 06:50:45
问题 In my application, when user logs in to the system the system reads some setting from DB and stores them on user's session. The system is performing this action by a JPA query using EclipseLink (JPA 2.0). When I change some settings in DB, and sign in again, the query returns the previous results. It seems that EclipseLink is caching the results. I have used this to correct this behavior but it does not work : query.setHint(QueryHints.cache_usage,cacheUsage.no_cache); 回答1: If you want to set

Spring JPA : Application managed persistence context with @Transactional and @PersistenceContext

放肆的年华 提交于 2019-12-07 03:52:19
问题 Currently im trying out the application managed persistence context, by creating the entity manager manually and store them to enable transaction that spans multiple request calls (perhaps something like extended persistence context) in JSE application. But, im wondering whether i can avoid sending the entityManager object throughout the service and DAO methods as an additional parameter by making use of the spring's @PersistenceContext injection and mark the methods with @Transactional

Is there a way to reduce the amount of boiler-plate code associated with a CriteriaQuery (in JPA 2.0)?

泪湿孤枕 提交于 2019-12-07 02:27:08
问题 I love the type safety CriteriaQuery brings ing JPA 2.0 but it also brings a bit of boiler-plate code. For example, let say I have an entity called NamedEntity, which simply has an id and a String field called "name" (assume it has the unique constraint set to true). Here's what the NamedEntityManager might look like: public class NamedEntityManager { //inject using your framework EntityManager entityManager; //retrieve all existing entities of type NamedEntity from DB public Iterable

Transaction and Rollback in Spring with JPA

混江龙づ霸主 提交于 2019-12-07 02:24:28
Hi friends of StackOverflow, I do not understand how to roll back I read the documentation of Spring, but I still do not understand. Basically I'm going to persist an object in the db (with primary key manually) all the way here all right, the object is inserted into the db. But when you persist the object again with the same primary key I have caused an exception, and rightly so, a violation of restriction of uniqueness. In this case I would get a Transaction rollback and warn you that there was the problem and continue running the program This is my class: public class ServiceDaoImpl{