jpa-2.0

JavaEE 6: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null

烈酒焚心 提交于 2019-12-11 12:11:49
问题 Yesterday when I was working on my JavaEE application, it was happily getting deployed to Glassfish 3.1 and all the [web, ejb, jpa] engines were working and I was able to interact with database without any problem. But ever since I started working today I've been having java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null error when I try to retrieve something from database. The application is still deploying without any problems but I can't see the [jpa]

How do I make my entity object managed so I can remove it?

£可爱£侵袭症+ 提交于 2019-12-11 10:24:51
问题 This doesn't work -- I always get the IllegalArgumentException thrown with the advice to "try merging the detached and try the remove again." @PersistenceContext private EntityManager em; @Resource private UserTransaction utx; public void delete(EN entity) { if (entity == null) return; // null-safe EN target = entity; try { if (!em.contains(entity)) { System.out.println("delete() entity not managed: " + entity); utx.begin(); target = em.merge(entity); utx.commit(); System.out.print("delete()

JPQL+ MYSQL to get rid of `You can't specify target table XXX for update in FROM clause`

谁说胖子不能爱 提交于 2019-12-11 09:46:16
问题 There is an AccessLog table which logs which user (FK user_id ) accesses which mail (FK mail_id ) at which time(column created ). The table grows as time goes by. I want to keep the latest row (which user last accesses which mail) , removing all old logs. The following SQL code works as expected: delete from AccessLog where id not in ( select id from ( select a.id from AccessLog a where a.created = (select max(b.created) from AccessLog b where b.user_id = a.user_id and b.mail_id = a.mail_id )

org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile

孤人 提交于 2019-12-11 09:32:52
问题 I have a many-to-many relationship in JPA 2.0 provided by Hibernate 4.2.0 CR1 (recently upgraded to Hibernate 4.2.7 final) between Product and Colour as follows. The Product entity class: public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "prod_id") private Long prodId; @JoinTable(name = "prod_colour", joinColumns = { @JoinColumn(name = "prod_id",

JPA 2 Remote Criteria?

北城余情 提交于 2019-12-11 09:15:38
问题 Is there any way that criteria for queries can be built on a remote (Swing/SWT etc) client? We've been using the DetachedCriteria functionality in Hibernate for quite some time, but would like to use standard JPA 2. If not, could the code from hibernate be re-factored to create the remote API? Or is this something that might come along in JPA 2.1? 回答1: Not to my knowledge. Consider leaving a comment on Linda DeMichiel's Blog (the spec Lead) or sending your input to the expert group: JPA.next

Hibernate: “no type name” with “AttributeConverter” on Map

…衆ロ難τιáo~ 提交于 2019-12-11 08:54:45
问题 I have this: @Column @Convert(converter = MyMapConverter.class) private Map<String, String> temp; MyMapConverter is a simple JPA-AttributeConverter: @Converter public class MyMapConverter implements AttributeConverter<HashMap<String, String>, String> { @Override public String convertToDatabaseColumn(HashMap<String, String> attribute) { return attribute.toString(); } @Override public HashMap<String, String> convertToEntityAttribute(String dbData) { return ... } } When starting the application,

How to enable weaving in EclipseLink?

大城市里の小女人 提交于 2019-12-11 07:46:41
问题 I receive the following warning on the GlassFish terminal while deploying an application that has lazy fetching in entities, WARNING: Reverting the lazy setting on the OneToOne or ManyToOne attribute [zoneTable] for the entity class [class entity.ZoneCharge] since weaving was not enabled or did not occur. for whatever entities are listed in the project. My persistence.xml file looks something like the following. <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http:/

QuerySyntaxException: expecting CLOSE, found '.'

青春壹個敷衍的年華 提交于 2019-12-11 07:46:02
问题 I want to rewrite this SQL query into JPQL and use JPA Projection: SELECT count(id) as count, status, error_class, error_message, id, settlement_status_raw FROM `payment_transactions` WHERE `payment_transactions`.`terminal_id` = 16 AND (created_at > '2019-06-01 00:00:00.000000') AND (`payment_transactions`.`status` != 'approved') GROUP BY `payment_transactions`.`error_message` ORDER BY count DESC I tried this: @Query(value = "SELECT new org.plugin.service.PaymentTransactionsDeclineReasonsDTO

How do I persist a detached object?

…衆ロ難τιáo~ 提交于 2019-12-11 07:07:54
问题 I have a simple editor UI for performing CRUD on a database table. Under Hibernate 5.1, the process was: Create a session. Read in data objects. Close session, detaching the objects. With the detached objects, populate the UI widgets. Allow user to add/edit/remove entries in the UI, modifying the detached objects. On a user "save" action: Create a new session. Persist new/updated objects with saveOrUpdate(). Close session. Repeat as required. Hibernate 5.2 strongly recommends moving from the

month() function and year() function in postgresql through jpa2

这一生的挚爱 提交于 2019-12-11 07:01:58
问题 How to get the month and year of a postgresql date field using jpa2 criteria query or jpql? Has anybody done this? 回答1: Use this: FUNC('MyFunc', a, b, c) Example: SELECT FUNC('to_char', current_date, 'month') 回答2: A few examples, how to extract the month from a date or timestamp in PostgreSQL: select to_char(now(), 'month'); select to_char(now(), 'MM'); select extract('month' from now()); select date_part('month', now()); Just read the manual. 回答3: With JPA criteria API (tested only with