0

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
john
  • 647
  • 5
  • 23
  • 53

1 Answers1

1

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.

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • 1
    Thank you. But I can't use native sql. Sql flavors differ with different databases. Create statement in oracle is different than create statement in mysql. – john Jul 13 '19 at 16:01