facebook

insert index not working

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #280726 Reply

    David
    Member

    I am running:

    Eclipse 6.0.1GA on XP
    SQL Server 2005
    Hibernate3.jar

    I 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,

    #280795 Reply

    Riyad Kalla
    Member

    sonoerin,
    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.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: insert index not working

You must be logged in to post in the forum log in