I have a problem with Hibernate 4.2.7.SP1 and I don’t know if this is a misuse or an error. I use hibernate with annotations, and my code is similar to these two objects:
First object:
@Entity
@Table(name = "TABLE1")
public class FirstObject {
@Id
@GeneratedValue
private Long id;
private SecondOBject secondObject
}
The second object:
@Entity
@Table(name = "TABLE2")
public class SecondObject {
@Id
@GeneratedValue
private Long id;
@ElementCollection
@CollectionTable(name = "T_MAPTABLE")
private Map<String, Integer> iAmAHashmap;
}
Of course, a lot of code was omitted because I think this is not relevant to the issue.
When I run a test where I create a "FirstObject" object with "SecondObject" and try to save it using hibernate, I see that this sleep mode generates this sql code:
Hibernate:
insert
into
TABLE2
values
( )
As you can see, there are no parameters and no values. Therefore, an exception is thrown:
SqlExceptionHelper [main] - [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
The map in SecondObject matters (I printed the size of the map to make sure). But Hibernate does not save it and tries to save empty parameters in TABLE2.
, SecondObject (.. ):
@Entity
@Table(name = "TABLE2")
public class SecondObject {
@Id
@GeneratedValue
private Long id;
private String dummyText="hello!";
@ElementCollection
@CollectionTable(name = "MAPTABLE")
private Map<String, Integer> iAmAHashmap;
}
, Hibernate:
Hibernate:
insert
into
TABLE2
(dummyText)
values
(?)
, , (, , ).
hibernate.cfg.xml:
....
<property name="hibernate.hbm2ddl.auto">create-drop</property>
....
MAPTABLE .
:
hibernate ?
? ( , ).