john
john

Reputation: 707

How to create NO primary key table with Hibernate?

My goal is to create a no PK table in the database (I will never use it for ORM). I only need to create it, that's all.

I know it is possible to create a no PK table with NHibernate from this stack overflow question Why is NHibernate creating a table without primary key? But I need it to work in Java not .Net

Here is what works. It has PK, but I don't need it

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class entity-name="testtablenopi">
<id name="id"
            type="long"
            column="ID">
            <generator class="sequence"/>
</id>

<property name='xarxint'  column='xarxint'    type='int' precision='11' scale='0'/>
<property name='xarxbig_decimal'  column='xarxbig_decimal'    type='big_decimal'  precision='17' scale='2'/>
</class>

When I remove <id/> it doesn't work .

I tried replacing class with bag it didn't work.

How can I create a database table without a PI in hibernate?

Upvotes: 0

Views: 695

Answers (1)

Augusto
Augusto

Reputation: 29827

It's not possible. Hibernate and all ORMs I know require a PK to be defined for an object.

You'll need to use a plain old JDBC insert statement.

Upvotes: 1

Related Questions