thatmikewilliams wrote:
What does the generated sql look like? Is hibernate definitely trying to set the ID column? It would be helpful to see your mapping file/annotations for the class in question.
Here is the full debugging output generated before the error:
DEBUG - opened session at timestamp: 12208764619
DEBUG - begin
DEBUG - opening JDBC connection
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - current autocommit status: true
DEBUG - disabling autocommit
DEBUG - after transaction begin
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: com.foo.jpaweb.model.Author
DEBUG - merging transient instance
DEBUG - saving [com.foo.jpaweb.model.Author#<null>]
DEBUG - executing insertions
DEBUG - Wrapped collection in role: com.foo.jpaweb.model.Author.books
DEBUG - executing identity-insert immediately
DEBUG - Inserting entity: com.foo.jpaweb.model.Author (native id)
DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - insert into dbo.authors (name, id) values (?, ?)
Hibernate: insert into dbo.authors (name, id) values (?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [com.foo.jpaweb.model.Author#<null>]
DEBUG - binding 'sdfsd' to parameter: 1
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - could not insert: [com.foo.jpaweb.model.Author] [insert into dbo.authors (name, id) values (?, ?)]
java.sql.SQLException: Parameter #2 has not been set.
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareSQL(ConnectionJDBC2.java:613)
So it looks like the SQL is:
insert into dbo.authors (name, id) values (?, ?)
My persistence.xml file is:
<persistence>
<persistence-unit name="jpaweb" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="mypassword"/>
<property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://localhost:1433/demo;instance=sqlserver"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.connection.release_mode" value="auto" />
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.DriverManagerConnectionProvider" />
</properties>
</persistence-unit>
</persistence>
And my entity file is actually written in scala, but should still make sense for non-scala guys:
@Entity
@Table(){val name="authors", val schema="dbo"}
class Author {
// the _ is just a scala convention for saying "Any", or in this case, any Long.
@Id
@GeneratedValue(){val strategy = GenerationType.IDENTITY}
var id : Long = _
var name : String = ""
@OneToMany(){val mappedBy = "author", val targetEntity = classOf[Book]}
var books : java.util.Set[Book] = new java.util.HashSet[Book]()
}
As you can see, its very simple. Im just trying to get a tester working, so im not sure why such a simple example is going wrong.
Does that illuminate the problem at all?
Cheers
Tim