jpa-2.0

@Column insertable, updateble don't go well with Spring JPA?

北城以北 提交于 2019-11-29 13:09:30
Scenario : I have 3 tables, Offer, Channel and Offer_Channels. Basically Channel is a lookup table, i.e, the values in that table can neither be inserted nor updated by the application. An offer can contain one or many channels. I use the Channel table values to populate dynamic checkboxes. Anyways, so here is what I have : @Entity @Table(name = "OFFER") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class Offer implements Serializable { // Offer Id @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "offer_seq_gen") @Column(name = "OFFER_ID") private long

select from two tables using JPQL

扶醉桌前 提交于 2019-11-29 11:15:39
I'm using JPQL to retrieve data. I can get data using the statement List persons = null; persons = em.createQuery("select p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1"); Now I can get the album names using this: int i=0; for (i=0;i<persons.size(); i++) { System.out.println("Testing n "+ i +" " + persons.get(0)); } Now I want to get the album name and the roleuser's row named firstname I'm using the query persons = em.createQuery("select r.firstName , p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1").getResultList(); Now how do I

How to map postgresql “timestamp with time zone” in a JPA 2 entity

▼魔方 西西 提交于 2019-11-29 10:48:39
问题 I have a JPA 2 application ( with Hibernate 3.6 as the JPA implementation ) that uses Postgresql ( with the 9.0-801.jdbc3 JDBC driver ). I am having trouble mapping "timestamp with time zone" fields into my JPA entities. Here is an example: CREATE TABLE theme ( id serial NOT NULL, # Fields that are not material to the question have been edited out run_from timestamp with time zone NOT NULL, run_to timestamp with time zone NOT NULL, CONSTRAINT theme_pkey PRIMARY KEY (id ), CONSTRAINT theme

How do you create an EntityManager when you are unsure of the unit name?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 10:31:37
I'm in a situation where I need to determine the EntityManager's unit name at run time. For example, I'd like to do something like this: @PersistenceContext(unitName = findAppropriateJdbcName()) EntityManager entityManager; However, this is not possible with annotations. Is it possible to create the EntityManager when your not sure of what the unit name is until run time? Jim Tough It is possible to specify the persistence unit (PU) name at runtime, but this is a parameter used in the creation of the EntityManagerFactory , not an individual EntityManager . See the Javadoc for the Persistence

Does JPA 2.0 support SQL Server table variables?

时光怂恿深爱的人放手 提交于 2019-11-29 08:47:35
I am using JPA 2.0 and SQL Server 2008 and I have determined that JPA doesn't like my stored procedures when I use a table variable. For example, this sproc works: declare @t table ( id int identity , test varchar(50) ) select 'blah' as test -- I'm ignoring the table variable above However, when I try to insert something into the table variable @t with this code, it crashes: declare @t table ( id int identity , test varchar(50) ) insert into @t select cast(getdate() as varchar(60)) select * from @t I get the following error: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2

@OrderColumn, @OneToMany & null index column for collection

本秂侑毒 提交于 2019-11-29 08:38:02
问题 I am trying to create parent child tables where the order is preserved. The example 7.8 from Hibernate documentation shows how to do this: @Entity public class Customer { @Id @GeneratedValue public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } private Integer id; @OneToMany(mappedBy="customer") @OrderColumn(name="orders_index") public List<Order> getOrders() { return orders; } public void setOrders(List<Order> orders) { this.orders = orders; } private List

JPA2 Criteria queries on entity hierarchy

三世轮回 提交于 2019-11-29 07:32:06
suppose i have the following entity domain: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="TYPE") public abstract class Entity1 { //some attributes } @Entity @DiscriminatorValue("T1") public class Entity2 extends Entity1 { @OneToMany(fetch=FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy="parent") @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private Set<Entity1Detail> details = new HashSet<Entity1Detail>(); } @Entity public class Entity1Detail { @ManyToOne @JoinColumn(name="REF") private Entity2 parent; @Basic private Integer

How to create an 'instance of' -like query in JPA 2.0?

强颜欢笑 提交于 2019-11-29 07:28:26
问题 Say we've got an abstract @Entity Animal, and several entity classes that extend Animal, including Dog, Cat, Monkey and Bat. How can I filter the results based on the extending entity's class? Example : There are checkboxes where the user can select which entities to retrieve. [ ] Dog [X] Cat [X] Monkey [ ] Bat Now I want to retrieve the entities with a (Named)Query defined in the Animal class. What kind of query parameters can I put into the query so that only the Cat and Monkey objects will

Is there a way to expose Hibernate Entities as RESTful resources without DTOs?

南笙酒味 提交于 2019-11-29 07:18:56
I am developing a simple webapp which exposes the domain model as RESTful resources. I am planning to use JPA2(Hibernate) with SpringMVC REST support. While marshalling Hibernate entities into XML/JSON, if the entity is detached it will throw LazyLoadingException for lazy child associations. If the entity is still attached to Hibernate Session it will almost load whole database. I have tried using Dozer CustomFieldMapper to determine if the property is lazy Hibernate Collection which is not loaded then return NULL. But if we have bi-directional associations Hibernate eagerly load Many-to- One

PostGIS and JPA 2.0

感情迁移 提交于 2019-11-29 07:01:34
I'd like to map datatypes from PostGIS with JPA 2.0. I googled for solutions or examples, but all I can find is that JPA does not support mapping of custom data types. Is it still like this in JPA 2.0? Has anybody a hint for an example? I googled for solutions or examples, but all I can find is, that JPA does not support mapping of custom data types. Is it still in JPA 2.0? Yes. So you'll have to rely on specific extensions. For Hibernate, the Hibernate Spatial project provides ready to use spatial dialects and custom types: Hibernate Spatial is a generic extension to Hibernate for handling