Hibernate version: version 3.2.4.sp1, May 18, 2007
Hibernate Annotation version: Version: 3.3.0.GA, 19.03.2007
Name and version of the database you are using:Oracle 8.1.7
I copied this example from the reference documentation that comes with the 3.3.0 GA documentation.
(hibernate-annotations-3.3.0.GA/doc/reference/en/html_single/index.html#entity-mapping-association)
Its the example from the "2.2.5.1. One-to-one" section describing a one-to-one using an association table.
The following execption is thrown. Any ideas?
org.hibernate.PropertyValueException: not-null property references a null or transient value:
If I make this uni-directional by removing the "owner" property from the Passport class it works.
Code:
package com.test.onetoone.bad;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToOne;
@Entity
public class Customer implements Serializable
{
@Id
public long custumerID;
@OneToOne(cascade = CascadeType.ALL)
@JoinTable(name = "CustomerPassports",
joinColumns = @JoinColumn(name="customer_fk"),
inverseJoinColumns = @JoinColumn(name="passport_fk")
)
public Passport passport;
}
Code:
package com.test.onetoone.bad;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class Passport implements Serializable
{
@Id
public long passportID;
@OneToOne(mappedBy = "passport")
public Customer owner;
}
Code:
package com.test.onetoone.bad;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class Test1
{
public static void main(String[] args)
{
try
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
Customer cust = new Customer();
cust.custumerID=1;
Passport pass = new Passport();
pass.passportID=2;
cust.passport=pass;
pass.owner=cust;
session.saveOrUpdate(cust);
tx.commit();
}
catch(Exception ex)
{
System.err.println(ex);
}
}
}
When ran, it gives the following error:
Code:
12:17:43,625 INFO Version:15 - Hibernate Annotations 3.3.0.GA
12:17:43,656 INFO Environment:514 - Hibernate 3.2.4.sp1
12:17:43,656 INFO Environment:547 - hibernate.properties not found
12:17:43,656 INFO Environment:681 - Bytecode provider name : cglib
12:17:43,671 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
12:17:43,781 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
12:17:43,781 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
12:17:44,140 INFO Configuration:553 - Reading mappings from resource : orm.xml
12:17:44,578 INFO Configuration:1541 - Configured SessionFactory: null
12:17:44,765 INFO AnnotationBinder:398 - Binding entity from annotated class: com.test.onetoone.bad.Customer
12:17:44,828 INFO EntityBinder:420 - Bind entity com.test.onetoone.bad.Customer on table Customer
12:17:44,890 INFO EntityBinder:631 - Adding secondary table to entity com.test.onetoone.bad.Customer -> CustomerPassports
12:17:44,921 INFO AnnotationBinder:398 - Binding entity from annotated class: com.test.onetoone.bad.Passport
12:17:44,921 INFO EntityBinder:420 - Bind entity com.test.onetoone.bad.Passport on table Passport
12:17:45,015 INFO AnnotationConfiguration:350 - Hibernate Validator not found: ignoring
12:17:45,031 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
12:17:45,031 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 2
12:17:45,031 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
12:17:45,093 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@127.0.0.1:1521:TESTDB
12:17:45,093 INFO DriverManagerConnectionProvider:86 - connection properties: {user=abc123, password=****}
12:17:45,640 INFO SettingsFactory:89 - RDBMS: Oracle, version: Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
12:17:45,640 INFO SettingsFactory:90 - JDBC driver: Oracle JDBC driver, version: 9.2.0.5.0
12:17:45,656 INFO Dialect:152 - Using dialect: org.hibernate.dialect.OracleDialect
12:17:45,671 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
12:17:45,671 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:17:45,671 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
12:17:45,671 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
12:17:45,671 INFO SettingsFactory:154 - JDBC batch size: 15
12:17:45,671 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
12:17:45,671 INFO SettingsFactory:162 - Scrollable result sets: enabled
12:17:45,671 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
12:17:45,671 INFO SettingsFactory:178 - Connection release mode: auto
12:17:45,687 INFO SettingsFactory:205 - Default batch fetch size: 1
12:17:45,687 INFO SettingsFactory:209 - Generate SQL with comments: disabled
12:17:45,687 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
12:17:45,687 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
12:17:45,687 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:17:45,687 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
12:17:45,687 INFO SettingsFactory:225 - Query language substitutions: {}
12:17:45,687 INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
12:17:45,687 INFO SettingsFactory:235 - Second-level cache: enabled
12:17:45,687 INFO SettingsFactory:239 - Query cache: disabled
12:17:45,687 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
12:17:45,687 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
12:17:45,687 INFO SettingsFactory:263 - Structured second-level cache entries: disabled
12:17:45,703 INFO SettingsFactory:283 - Echoing all SQL to stdout
12:17:45,703 INFO SettingsFactory:290 - Statistics: disabled
12:17:45,703 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
12:17:45,703 INFO SettingsFactory:309 - Default entity-mode: pojo
12:17:45,703 INFO SettingsFactory:313 - Named query checking : enabled
12:17:45,734 INFO SessionFactoryImpl:161 - building session factory
12:17:46,250 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
12:17:46,250 INFO AnnotationConfiguration:350 - Hibernate Validator not found: ignoring
12:17:46,265 INFO AnnotationConfiguration:350 - Hibernate Validator not found: ignoring
12:17:46,265 INFO SchemaExport:154 - Running hbm2ddl schema export
12:17:46,265 DEBUG SchemaExport:170 - import file not found: /import.sql
12:17:46,265 INFO SchemaExport:179 - exporting generated schema to database
12:17:46,265 DEBUG SchemaExport:303 -
drop table Customer cascade constraints
12:17:46,312 DEBUG SchemaExport:303 -
drop table CustomerPassports cascade constraints
12:17:46,343 DEBUG SchemaExport:303 -
drop table Passport cascade constraints
12:17:46,359 DEBUG SchemaExport:303 -
create table Customer (
custumerID number(19,0) not null,
primary key (custumerID)
)
12:17:46,390 DEBUG SchemaExport:303 -
create table CustomerPassports (
customer_fk number(19,0) not null,
passport_fk number(19,0),
primary key (passport_fk)
)
12:17:46,406 DEBUG SchemaExport:303 -
create table Passport (
passportID number(19,0) not null,
primary key (passportID)
)
12:17:46,437 DEBUG SchemaExport:303 -
alter table CustomerPassports
add constraint FK624ED0432A8EE827
foreign key (passport_fk)
references Passport
12:17:46,453 DEBUG SchemaExport:303 -
alter table CustomerPassports
add constraint FK624ED043BB22C4A7
foreign key (customer_fk)
references Customer
12:17:46,453 INFO SchemaExport:196 - schema export complete
Hibernate:
select
customer_.custumerID,
customer_1_.passport_fk as passport2_1_
from
Customer customer_,
CustomerPassports customer_1_
where
customer_.custumerID=?
and customer_.custumerID=customer_1_.customer_fk(+)
Hibernate:
select
passport_.passportID,
passport_1_.customer_fk as customer0_1_
from
Passport passport_,
CustomerPassports passport_1_
where
passport_.passportID=?
and passport_.passportID=passport_1_.passport_fk(+)
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.test.onetoone.bad.Passport.owner