jpa-2.0

Exclude JPA 2.0 from JBoss 7.1 in order to use hibernate 4.3

浪尽此生 提交于 2019-11-29 01:42:19
问题 I want to use hibernate 4.3 for its multitenancy features in JBoss 7.1. I managed to include it in my war by adding the following lines in jboss-deployment-structure <exclusions> <module name="org.hibernate" /> </exclusions> and adding a dependency to hibernate core and entity manager in my pom.xml This made hibernate 4.3 to load but unfortunately I got an error java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; which is due to JPA 2.0 being loaded when

How to get the primary key of any JPA entity?

删除回忆录丶 提交于 2019-11-29 01:39:20
For every @Entity I need to perform the following: public <Entity> boolean insert(final Entity entity){ if (em.find(entity.getClass(), entity.getId()) == null) { et.begin(); em.persist(entity); et.commit(); return true; } return false; } That is persist the entity if it didn't exist, and know if it did or not exist. With Entity I'm trying to reach @Entity, although I realize it's not an inheritance relationship. What class can I use to refer to every JPA entity? I could just create an interface/abstract class MyEntities and have all of them inherit, but is that the way? I'm hoping for less

Constraint violation in Hibernate unidirectional OneToMany mapping with JoinTable and OrderColumn when removing elements

眉间皱痕 提交于 2019-11-29 01:04:02
问题 I have a problem when removing elements from a list mapped as described above. Here is the mapping: @Entity @Table( name = "foo") class Foo { private List bars; @OneToMany @OrderColumn( name = "order_index" ) @JoinTable( name = "foo_bar_map", joinColumns = @JoinColumn( name = "foo_id" ), inverseJoinColumns = @JoinColumn( name = "bar_id" ) ) @Fetch( FetchMode.SUBSELECT ) public List getBars() { return bars; } } Inserting Bar-instances and saving the Foo works fine, but when I remove an element

Upload, Insert, Retrieve and Display Image using JPA JSF MySql [closed]

空扰寡人 提交于 2019-11-29 00:57:38
问题 I am asking this question and I intend to answer the question for others to learn. Its pretty simple and straight forward. I Hope it helps. This is it Create your entity for example customer with your blob field @Entity public class Customer implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Lob private byte[] logo; //setter and getter required Create a session Bean to help communicate with the

JPA table with 2 primary key fields

ぐ巨炮叔叔 提交于 2019-11-29 00:53:13
问题 I have a table which contains only 2 fields. The table has a composite PK formed by these two fields. When using Netbeans for creating entity beans from database, the entity bean is not created automatically like other tables that have more than 2 fields. So I guess I need to create the entity bean myself. What is the best practice for creating this entity bean? Does it have to contain COMPOSITE KEY object or not? 回答1: I don't use NetBeans so I can't really say anything about its mapping

A concise, clear list of what is new in JPA2?

别来无恙 提交于 2019-11-28 23:52:58
问题 Does anybody know of a good list of what is new in JPA 2? Not what is new with Hibernate/TopLink in the version that supports JPA 2 but what is new in the actual spec. 回答1: The link mentioned in the accepted answer doesn't say anything about the second level cache so I decided to post a quick list to summarize "What's new in JPA 2.0 (JSR-317)": Standard properties for persistence.xml - E.g. javax.persistence.jdbc.driver , etc instead of persistence provider specific properties. Mixed Access

How do I count the number of rows returned by subquery?

删除回忆录丶 提交于 2019-11-28 23:28:07
I want to do something like this: select count(*) from (select ...) (As it would be in SQL), but in JPA. Any ideas on how I would do it? pkainulainen This should do the trick (If you want to use JPA criteria API): CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<Entity> root = query.from(Entity.class); //Selecting the count query.select(cb.count(root)); //Create your search criteria Criteria criteria = ... //Adding search criteria query.where(criteria); Long count = getEntityManager().createQuery(query).getSingleResult()

How to make a CriteriaBuilder join with a custom “on” condition?

こ雲淡風輕ζ 提交于 2019-11-28 23:10:57
I want make a query where I join 2 tables, using the CriteriaBuilder. In MySQL the query I'm trying to make would look like this: SELECT * FROM order LEFT JOIN item ON order.id = item.order_id AND item.type_id = 1 I want to get all orders and if they have an item of type #1, I want to join with this item. However, if no item of type #1 is found, I still want to get the order. I can't figure out how to make this with the CriteriaBuilder. All I know how to make is: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Order> cq = cb.createQuery(Order.class); Root<Order> order = cq.from

JPA's cascade = REMOVE and Hibernate's @OnDelete used together?

混江龙づ霸主 提交于 2019-11-28 21:42:34
I have inherited a code base on which nearly all relations have the following annotations: @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "someThing") @OnDelete(action = OnDeleteAction.CASCADE) Now I'm having trouble understanding what @OnDelete does in the first place. Hibernate: OnDelete vs cascade=CascadeType.REMOVE is interesting, but unfortunately doesn't have any answers and the JavaDoc for @OnDelete is particularly worthless. From the other questions it looks like the OnDelete annotation somehow lets the DB do the cascading, while the cascading directive

EntityManager ThreadLocal pattern with JPA in JSE

纵然是瞬间 提交于 2019-11-28 21:32:49
I'm developing a simple "Book Store" project using Struts 1.3 + JPA (with Hibernate as persistence provider). I cannot switch to Spring or any other more sophisticated development environment (e.g., Jboss) and I cannot use any Hibernate-specific technique (e.g., Session class). Given the fact that I'm in a JSE Environment, I need to explicitly manage the whole EntityManager's lifecycle. The Book entity is defined as follows: @Entity public class Book { @Id private String isbn; private String title; private Date publishDate; // Getters and Setters } I defined three Action classes, which are