hibernate-mapping

Hibernate @OneToMany throws MySQLSyntaxErrorException: You have an error in your SQL syntax

≯℡__Kan透↙ 提交于 2019-12-06 07:11:27
I try to retrieve a list with some fields from Contact and also a list of phones. For this, I'm using a query to Contacts; Also I've created a DTO with only that fields that I need. The query is: final StringBuilder query = new StringBuilder(); query.append("SELECT new com.tim.core.dto.client.MinimalContactDTO(c.id, c.version, c.name, c.title, c.email, c.createdDate, c.phones) " + " from CONTACT c "); query.append("where "); query.append("( c.localRecordStatus IS NULL "); query.append("OR c.localRecordStatus IN (:openStatusList) "); query.append(" ) "); return em.createQuery(query.toString(),

Mapping a Map<String, Double> with Hibernate and JPA

别等时光非礼了梦想. 提交于 2019-12-06 06:42:38
问题 I try the following mapping @ElementCollection private Map<String, Double> doubleValues; But when I generate my schema from this (using mvn hibernate3:hbm2ddl ), I get the following errors: org.hibernate.MappingException: Could not determine type for: java.util.Map, at table: ImagerAnalysisResult, for columns: [org.hibernate.mapping.Column(doubleValues)] I've tried adding column and type information to this, but I keep getting the same error. Also, I don't think that information should be

How do I configure JPA table name at runtime?

对着背影说爱祢 提交于 2019-12-06 06:09:55
问题 I have an issue where I have only one database to use but I have multiple servers where I want them to use a different table name for each server. Right now my class is configured as: @Entity @Table(name="loader_queue") class LoaderQueue I want to be able to have dev1 server point to loader_queue_dev1 table, and dev2 server point to loader_queue_dev2 table for instance. Is there a way i can do this with or without using annotations? I want to be able to have one single build and then at

Stripping trailing whitespace from char fields in a legacy database with Grails GORM

99封情书 提交于 2019-12-06 03:19:40
问题 What are the possible solutions for stripping the trailing whitespace when mapping char fields in a legacy database? I see the following options: Calling .trim() at the point of use (controller, view, etc) Override property accessors to return .trim() Using a Hibernate UserType to trim the whitespace I'm leaning toward overriding the property accessor so that the domain properties remain consistent throughout the application. 回答1: I had a similar problem and I could not alter the legacy data.

How to use Oracle query hint in Hibernate

蹲街弑〆低调 提交于 2019-12-06 00:49:13
I am trying to use Oracle hint in Hibernate to call force index, but didn't find any proper API in Hibernate 3.6.10.Final. I somehow tried with projections in Hibernate criteria: proList.add(Projections.sqlProjection("/*+ INDEX_DESC(CONTACT_USER_FK_I) */", new String[]{}, new Type[]{})); proList.add(Projections.property("objectId")); criteria.setProjection(proList); return criteria.list(); But I am getting the exception below: EXCEPTION Caused by: 8 SQL Error (could not execute query; SQL [select /*+ INDEX_DESC(CONTACT_USER_FK_I) */, this_.CONTACT_ID as y0_ from R4GDEV01_MBW.CONTACT this_ w

Mapping a table called “group” in Hibernate for DB2 and HSQLDB

柔情痞子 提交于 2019-12-05 20:52:52
I have a table called group , that I am trying to map using hibernate for DB2 and HSQLDB . Table name group is a reserved word and it must be quoted in HSQLDB. However DB2 does not like quoted table name. So this mapping works in HSQLDB but not in DB2: @Entity @Table(name="`group`") public class Group { Mapping results in following error in DB2 (making a query that involves Group table): Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: SCHEMA_NAME.group at com.ibm.db2.jcc.b.hh.c(hh.java:1662) at com.ibm.db2.jcc.b.hh.d(hh.java:1650) at com.ibm

Error testing DAOs: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class

雨燕双飞 提交于 2019-12-05 17:29:52
I am very new to Spring + Hibernate, and I am running tests to see if my DAOs are working. I get the following error which upon searching in Google yields a lot of different answers (mostly of typos, which I have checked). I'm hoping you can help me out on this: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) at org.springframework

Hibernate auto-increment property

元气小坏坏 提交于 2019-12-05 10:31:40
I know you can auto-increment an id by mapping; <id column="user_id" name="id" > <generator class="increment"/> </id> But is it also possible increment a property, what I tried so far didn't work; <property column="numeric_value" name="nr" > <generator class="increment"/> </property> But is it also possible increment a property, what I tried so far didn't work; No, you can't use a <generator> inside a <property> (or, to write it in plain english, Hibernate only supports using a generator for identifier properties). Maybe have a look at generated properties if you can rely on the database to

One to many hibernate join if column names are different

你说的曾经没有我的故事 提交于 2019-12-05 07:35:52
I have three tables with following structure - Contract -> contract_id(primary), customer_company_id, Vendor_company_id Company -> Company_id(primary), creation_date, created_by Company_Timeline -> Timeline_id(Primary), Company_id, Company_name. and have following classes for these tables - Contract.java @Table(name = "CONTRACT") @Entity @SequenceGenerator(name = "ContractSeq", sequenceName = "SEQCONTRACT", allocationSize = 1) public class Contract implements Serializable { private static final long serialVersionUID = 1L; /* * General Tab */ @Id @Column(name = "CONTRACT_ID") @GeneratedValue

How to exclude an entity field when doing an update with JPA

自古美人都是妖i 提交于 2019-12-05 07:32:47
Is there a way to make a field non-persistent at update operation but persistent at create operation with JPA - Hibernate 4? I tried it in this way @Transient @Id @Column(name = "USER_NAME", nullable = false, length = 75) private String userName; but with @Transient annotation the field will be transient across all CRUD operations and I want a way to specify that only on this operation is persistent (create). Is there a way to do this? Thanks! As explained in this article , you need to set updatable to false : @Column(name = "USER_NAME", nullable = false, length = 75, updatable= false) private