Why does hibernate create a query with no values?

A month ago I posted this question. Why is hibernate trying to execute a garbled request? And the solution solved the problem.

Now the error appears again in another very similar object, and the proposed solution does not solve the problem. Then, probably, the error was still in another place.

I rewrote a simplified example here:

First object:

@Entity
@Table(name = "TABLE1")
public class FirstObject { 
   @Id
   @GeneratedValue
   private Long id; // database id

   //Added as suggested in the previous solution. 
   @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   @JoinColumn(name = "object2Id")
   private SecondOBject secondObject;

   //Getters, setters and other stuff here.
}

The second object:

@Entity
@Table(name = "TABLE2")
public class SecondObject {
    @Id
    @GeneratedValue
    private Long object2Id; // database id.

    @ElementCollection   
    @CollectionTable(name = "T_MAPTABLE")
    private Map<String, Integer> iAmAHashmap;

    //More maps of Strings and Integers similar to the previous one, the getters, setters and other stuff.
 }

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 in my previous question, no parameters or values ​​are inserted again and hence the error:

SqlExceptionHelper [main] - [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)

I can print the values ​​of the map, and it has values ​​before saving, therefore it is not empty.

, , Hibernate . , . , . , , (, - Hibernate).

?

:

hibernate.cfg.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration>
<session-factory>
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="dialect">org.hibernate.dialect.SQLiteDialect</property>
    <property name="connection.driver_class">org.sqlite.JDBC</property>
    <property name="connection.url">jdbc:sqlite:database-test.db</property>
    <property name="connection.username"></property>
    <property name="connection.password"></property>         
    <property name="hibernate.hbm2ddl.auto">create-drop</property>

<mapping class="com.packet.FirstObject"></mapping>
<mapping class="com.packet.SecondObject"></mapping>
    //More classes here. 
</session-factory>
</hibernate-configuration>

src/test/resources, maven testng.

+4
1

, , "org.hibernate.dialect.SQLiteDialect".

postgres (org.hibernate.dialect.PostgreSQLDialect), .

+1

All Articles