Java – ID generation of hibernate, liquibase and HSQLDB
                                        
                    •
                    Java                                    
                I created a table with liquibase:
<createTable tableName="employees">
    <column name="id" type="bigint">
        <constraints primaryKey="true" nullable="false"/>
    </column>
    <column name="name" type="varchar(50)">
        <constraints nullable="false"/>
    </column>
</createTable>
Generate the following SQL DDL query:
CREATE TABLE employees (id BIGINT NOT NULL,name VARCHAR(50) NOT NULL,CONSTRAINT PK_EMPLOYEES PRIMARY KEY (id));
Corresponding entity:
@Entity
@Table(name="employees")
public class EmployeeAccessProperty ...
    @Id
    @GeneratedValue
    public long getId() {
        return id;
    }
...
Now, when I try to save it through the JPA implementation, generate an SQL query to insert data:
Hibernate: insert into employees (id,name) values (default,?) 2013-05-20T14:29:22.525+0700 WARN sql Error: -5544,sqlState: 42544 2013-05-20T14:29:22.526+0700 ERROR DEFAULT keyword cannot be used as column has no DEFAULT
I expect hibernate to select the best policy based on the provider when I do not specify the ID generation policy I don't understand why ID generation attempts to use default values I'm not sure which party is responsible for the error: Hibernate, liqubase or HSQLDB
What can I do to solve the problem? Please help me
Solution
You did not tell the database that the primary key must be generated automatically Create the table this way:
CREATE TABLE employees (id BIGINT GENERATED BY DEFAULT AS IDENTITY,CONSTRAINT PK_EMPLOYEES PRIMARY KEY (id));
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        