I have Oracle database.
In my table i have trigger, which fire up when some row is inserted. That works fine, when i use it from SQLDeveloper. But in Java I want to insert some row using Hibernate 3.3. Te body of my trigger is not really important, let's say it defines id of the row upon current time.
My POJO entity looks like:
@Entity
@Table( name = "user" )
public class User implements Serializable
{
private static final long serialVersionUID = 1;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( nullable = true, length = 14, name = "user_id" )
private Long userId;
@Column( nullable = true, length = 80, name = "name" )
private String name;
//getters and setters
}
Here is my code for persisting new user:
SessionFactory sessionFactory = sessionFactoryManager.getCurrentSession();
Session session = sessionFactory.openSession();
User user = new User();
user.setName("TEST");
session.persist(user);
session.flush();
As you can see I don't set the userId field because it should be set by my trigger before inserting a row, but it doesn't work. I found, that trigger will be called if I add @GeneratedValue annotation, but it seems it doesn't work on Oracle database: I have an error:
Dialect does not support identity key generation
Trying to resolve this error I only found articles about using sequence, but I don't want to use sequence, I have to use trigger.