jpa-2.0

Best configuration of c3p0 [closed]

微笑、不失礼 提交于 2019-11-27 09:59:36
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm struggling with a problem facing c3p0 configuration. I posted a question last week 回答1: This is a configuration I am using which keeps resources to a minimum. Of course you'll want to tailor your application

Hibernate JPA, MySQL and TinyInt(1) for Boolean instead of bit or char

*爱你&永不变心* 提交于 2019-11-27 09:58:20
问题 Here is my JPA2 / Hibernate definition: Code: @Column(nullable = false) private boolean enabled; In MySql this column is resolved to a bit(1) datatype - which does not work for me. For legacy issues I need to map the boolean to a tinyint not to a bit. But I do not see a possibility to change the default datatype. Is there any? 回答1: Try the NumericBooleanType . For some reason this doesn't have a declared short type name so you'd have to use: @Column(nullable = false) @Type(type = "org

What to use: JPQL or Criteria API? [closed]

情到浓时终转凉″ 提交于 2019-11-27 09:14:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . My Java application is using JPA for object persistence. The business domain is very simple (just three classes are persistent, with 3-5 properties in each). Queries are simple as well. The question is which approach I should use: JPQL or Criteria API? 回答1: I'm pretty sure

Hibernate inserts duplicates into a @OneToMany collection

随声附和 提交于 2019-11-27 09:02:52
I have a question concerning Hibernate 3.6.7 and JPA 2.0. Consider following entities (some getters and setters are omitted for brevity): @Entity public class Parent { @Id @GeneratedValue private int id; @OneToMany(mappedBy="parent") private List<Child> children = new LinkedList<Child>(); @Override public boolean equals(Object obj) { return id == ((Parent)obj).id; } @Override public int hashCode() { return id; } } @Entity public class Child { @Id @GeneratedValue private int id; @ManyToOne private Parent parent; public void setParent(Parent parent) { this.parent = parent; } @Override public

Hibernate triggering constraint violations using orphanRemoval

ⅰ亾dé卋堺 提交于 2019-11-27 08:24:05
I'm having trouble with a JPA/Hibernate (3.5.3) setup, where I have an entity, an "Account" class, which has a list of child entities, "Contact" instances. I'm trying to be able to add/remove instances of Contact into a List<Contact> property of Account. Adding a new instance into the set and calling saveOrUpdate(account) persists everything lovely. If I then choose to remove the contact from the list and again call saveOrUpdate, the SQL Hibernate seems to produce involves setting the account_id column to null, which violates a database constraint. What am I doing wrong? The code below is

Subquery in From claus in JPA2 Criteria

限于喜欢 提交于 2019-11-27 08:21:10
问题 I have a data model where an account can have multiple users: class Account { Long id; } class User { Long id; @ManyToOne Account account; } I'd like to do the following query which displays the number of users of each account: select Account.id, NumUsers.num from Account, (select Account.id as account_id, count(User.id) as num from User join Account on User.account_id=Account.id group by Account.id) as NumUsers where Account.id=NumUsers.account_id; I know I can re-write this specific query

Injecting entity manager into managed bean

隐身守侯 提交于 2019-11-27 07:21:54
问题 It is possible to inject entity manager (or its factory) into jsf managed bean using @PersistenceContext (or @PersistenceUnit )? I Tried it but nothing, I obtain a NullPointerException. 回答1: Yes it is possible. This is the syntax. @PersistenceContext EntityManager em; You need to have a persistence.xml in your project. Btw: I'm running Glassfish 3. After this you can then use methods like em.createNamedQuery. Also remember the injection takes place after the constructor so if your trying to

Hibernate generates negative id values when using a sequence

只谈情不闲聊 提交于 2019-11-27 06:53:51
I have a class with the following definition: @Id @SequenceGenerator(name = "SEQ_ACE_WORKERS_QUEUE_STATS_ID", sequenceName = "SEQ_ACE_WORKERS_QUEUE_STATS_ID", allocationSize = 500) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ACE_WORKERS_QUEUE_STATS_ID") @Column(name = "ID") private long Id; When we ran it on Jboss 4.2.3 it worked fine and generated the proper ID's (starting from 1000+) Now we moved to jboss 7.1.1 and it generates negative ID's! (starting from -498 and going up) Any idea why this might happen? jrm I just ran into this issue when migrating from JBoss 6.1

@ManyToMany without join table (legacy database)

≯℡__Kan透↙ 提交于 2019-11-27 06:51:35
问题 I have to apply JPA in a legacy database with an awful design. Unfortunately is not possible to change it. Luckily is only for read-only access. One of the strangest things I found is a "many-to-many" relationship without a join (or intermediate) table. This is a simplification of the table structure: USER ACCESS ---- ------ ID int primary key ID int primary key NAME varchar2(20) NAME varchar2(20) ACCESS_GROUP int ACCESS_GROUP int ACCESS_GROUP columns can be repeated in both tables One USER

How do I query for only superclass entities in a jpql query?

点点圈 提交于 2019-11-27 06:49:48
问题 I have the following entities: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="orderType", discriminatorType=DiscriminatorType.STRING) @DiscriminatorValue(value="BASE") @Table(name = "orders") public class OrderEntity implements Serializable { ... and @Entity @DiscriminatorValue(value="RECURRING") public class RecurringOrderEntity extends OrderEntity{ ... I can find all the subclasses (RecurringOrderEntity) with the following jpql: Query q = em