jpa-2.0

Ehcache Vs Static map cache implementation

寵の児 提交于 2019-12-03 15:08:05
I have few tables with very few entries in them and they will never change dynamically . so i want to cache the whole table in memory to reduce load on DB. I can easily achieve that by a static Map and populating the map in a static block. i was wondering whether the same is possible in a more effective way by Ehcache + hibernate? The advantage of a real second-level cache over a static map is that you get the advantage of in-memory access by still keeping the same way of defining, accessing and traversing your entities: by using the Hibernate session (or entity manager). You may keep

Hibernate: How configure EntityManager in Hibernate?

故事扮演 提交于 2019-12-03 14:19:42
问题 I create a hibernate project with 'hibernate tools'provide by JBoss to Eclipse. Generated the Entities (POJO's) and then the DAO's. This way for example: @Entity @Table(name = "area", catalog = "project_schema", uniqueConstraints = @UniqueConstraint(columnNames = "area")) public class Area implements java.io.Serializable { private Integer id; private String area; public Area() { } public Area(String area) { this.area = area; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id",

Mapping Extra Attribute in a Join Table JPA 2

时间秒杀一切 提交于 2019-12-03 14:02:21
问题 I am trying to model this relationship following this link http://www.javaworld.com/javaworld/jw-01-2008/images/datamodel.gif Its the usual Many to Many relationship between Order and Products but I dont know how to add the extra columns in the Join table. @Entity @Table(name = "Orders") public class Order { @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "ORDER_LINES", joinColumns = { @JoinColumn(name = "ORDER_ID") }, inverseJoinColumns = { @JoinColumn(name = "PROD_ID") }) private

Some basic questions on Criteria from JPA 2.0

谁都会走 提交于 2019-12-03 13:55:26
问题 I discovered JPA 2.0 Criteria API today and want to learn it. Just went through some examples and try to do a hands on. I have a table fruit with columns: id, name, color, size, taste. The regular stuff: EntityManagerFactory emf = Persistence.createEntityManagerFactory("fruitManager"); EntityManager em = emf.createEntityManager(); //get the criteria builder CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Fruit> c = cb.createQuery(Fruit.class); How will the following query get

JPA: is @PrimaryKeyJoinColumn(…) the same as @JoinColumn(…, insertable = ?, updatable = ?)?

社会主义新天地 提交于 2019-12-03 13:05:53
问题 Can you derive from the JPA spec, if @PrimaryKeyJoinColumn(...) , which doesn't have the insertable and updatable parameters, is the same as @JoinColumn(..., insertable = false, updatable = false) or @JoinColumn(..., insertable = true, updatable = true) when used on regular (non-inheritance) associations? Should they be interchangable? What are the insertable and updatable properties set to? Are they set to anything at all? Note, I'm only targeting the read-only attribute that both (seem to)

Injecting JPA's Entity Manager in Hibernate's EmptyInterceptor

霸气de小男生 提交于 2019-12-03 12:38:15
I am using JPA-2.0 with Hibernate in my data access layer. For audit logging purposes, I am using Hibernate's EmptyInterceptor by configuring below property in persistence.xml: <property name="hibernate.ejb.interceptor" value="com.mycom.audit.AuditLogInterceptor" /> Where AuditLogInterceptor extends hibernate's ' org.hibernate.EmptyInterceptor '. public class AuditLogInterceptor extends EmptyInterceptor { private Long userId; public AuditLogInterceptor() {} @Override public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws

JPA. How do I subclass existing entity and keep its ID?

倖福魔咒の 提交于 2019-12-03 11:53:33
Assume I have two classic non-abstract JPA classes: Person and Student. @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private String id; // ... } @Entity public class Student extends Person { // ... } Now person having some id enters the university and becomes a student. How do I process that fact in JPA and keep person's id? student = new Student(); student.setPersonData(person.getPersonData()); student.setId(person.getId()); entityManager.persist(student); Code above produces 'Detached entity passed to

Entity must be managed to call remove

巧了我就是萌 提交于 2019-12-03 11:50:54
What's going on here? @Stateless @LocalBean public class AppointmentCommentDao { public void delete(long appointmentCommentId) { AppointmentComment ac = em.find(AppointmentComment.class, appointmentCommentId); if (ac != null) { em.merge(ac); em.remove(ac); } } @PersistenceContext private EntityManager em; } On the call to remove I get an IllegalArgumentException with the message being Entity must be managed to call remove: ...., try merging the detached and try the remove again. In your case merge is not needed, because ac is not deattached in any point between em.find and em.remove . In

Difference between findBy and findOneBy in Spring data JPA

别等时光非礼了梦想. 提交于 2019-12-03 11:29:51
问题 All i know so far is that FindBy can return multiple results while FindOneBy will return a single result or null when we use it the following way. List<Department> findByDepartmentName(String name); Department findOneByDepartmentId(Long Id); now, my question is, can i use findBy this way? Department findByDepartmentId(Long Id); If yes, Lets assume there are multiple records for given Id. On what basis does findBydepartmentId return a single record? Finally, When or Why should i not use findBy

JPA entity with a interface attribute, is it possible?

天大地大妈咪最大 提交于 2019-12-03 11:16:26
I have the following entity: @Entity public class TestCaseStep implements JPAEntity<Integer> { ... @Column(name="STEP_NUMBER") private Integer stepNumber; @Enumerated(EnumType.STRING) @Column(name="ACTION") private Action action; **@ManyToOne @JoinColumn(name="connector") private ScriptItem connector;** My attribute ScriptItem is a interface for 3 other classes. Is it possible to configure JPA to set the correct class id in runtime execution? Other resources: public interface ScriptItem { String getValue(); ScriptItemType getType(); } @Entity @Table(name="DAT_FEED_XML") public class FeedXml