- This topic has 1 reply, 2 voices, and was last updated 16 years, 10 months ago by Riyad Kalla.
-
AuthorPosts
-
DavidMemberI am running:
Eclipse 6.0.1GA on XP
SQL Server 2005
Hibernate3.jarI have a simple table as:
CREATE TABLE [dbo].[DirectoryType](
[id] [int] NOT NULL,
[description] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [id] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
UNIQUE NONCLUSTERED
(
[description] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]I used MyEclipse to reverse engineer the Hibernate mappings.
<class name=”DirectoryType” table=”DirectoryType” schema=”dbo” catalog=”ISM_Dev”>
<id name=”id” type=”java.lang.Integer”>
<column name=”id” />
<generator class=”native”></generator>
</id>
<property name=”description” type=”java.lang.String”>
<column name=”description” length=”50″ not-null=”true” unique=”true” />
</property>
</class>Here is my Java to persist:
DirectoryType dt = new DirectoryType();
dt.setId(null); // this actually makes no difference
dt.setDescription(“test directory type”);
session.saveOrUpdate(dt);I am able to select values out of the table, but not insert. I did a show-sql and get this on the insert:
Hibernate: insert into ISM_Dev.dbo.DirectoryType (description) values (?)
To me that says that the HSQL isn’t being build correctly (because the actual text isn’t in the sql, nor is the id referenced, but I am new to Hibernate so I don’t know for sure.I have searched and searched and all examples show the above code/configuration to be correct. I would greatly appreciate any help you can offer
thanks,
Riyad KallaMembersonoerin,
The show_sql flag will show you the generated JDBC SQL which is what you see, the “?” is a place holder that will have the value from the POJO injected at run time, so that’s actually OK.Also, do you get an error when you run the code, or are you just not seeing the physical value inserted in the DB? If you are not getting an error, then chances are this is just a session-caching issue and the value isn’t getting flushed to the DB yet. You can try and force it by setting the hibernate.connection.autocommit property to “true” in your hibernate.cfg.xml file, or by using a transaction to surround your saveOrUpdate operation, forcing the change to be persisted to the DB.
-
AuthorPosts