Hi,
I am seeing in my application an association list is padded with a null. It is the first item in the list. The application is deployed as an EJB as part of a enterprise application.
My association is a bi-directional One To Many association with a compound primary key. There is a primary key class too. CustomerInventoryPK
Customer---<-CustomerInventory
I notice the index variable in PersistentList.readFrom(ResultSet, CollectionPersister, CollectionAliases, Object) is set with a value of 1. Rather than 0 which means the following for loop in the method pads the list with a null item.
This causes my application to throw a NullPointerException.
Details of the entities in my application are below. The getters and setters have been excluded.
Code:
@Entity
@Table (name="TEST_CUSTOMER")
public class Customer implements Serializable
{
@Id
@GeneratedValue
@Column(name="C_ID")
private int id;
@OneToMany(mappedBy="customer", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
private List<CustomerInventory> customerInventories;
public List<CustomerInventory> getInventories()
{
return customerInventories;
}
Code:
@Entity
@Table(name="TEST_CUSTINVENTORY")
@IdClass(CustomerInventoryPK.class)
public class CustomerInventory implements Serializable
{
@Id
@GeneratedValue
@Column(name="CI_ID")
private Long id;
@Id
@Column(name = "CI_CUSTOMERID", insertable = false, updatable = false)
private int custId;
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="CI_CUSTOMERID")
private Customer customer;
Code:
public class CustomerInventoryPK implements Serializable {
private Long id;
private int custId;
Code:
<hibernate-mapping>
<class name="org.jboss.orm.test.entity.Customer" mutable="true" table="TEST_CUSTOMER">
<cache usage="transactional" include="all"/>
<id name="id" type="java.lang.Integer" column="C_ID" access="field">
<generator class="assigned"/>
</id>
<list name="customerInventories" access="field" table="TEST_CUSTINVENTORY" lazy="false" cascade="all">
<cache usage="transactional" include="all"/>
<key>
<column name="CI_CUSTOMERID" not-null="true"/>
</key>
<list-index column="CI_ID"/>
<one-to-many class="org.jboss.orm.test.entity.CustomerInventory"/>
</list>
</class>
</hibernate-mapping>
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="associationTest">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<class>org.jboss.orm.test.entity.Customer</class>
<class>org.jboss.orm.test.entity.CustomerInventory</class>
<class>org.jboss.orm.test.entity.CustomerInventoryPK</class>
<mapping-file>META-INF/hbm_order.xml</mapping-file>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.id.optimizer.pooled.prefer_lo" value="true" />
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.default_batch_fetch_size" value="200"/>
<property name="hibernate.jdbc.fetch_size" value="200"/>
<property name="hibernate.jdbc.batch_size" value="16"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.archive.autodetection" value="true" />
</properties>
</persistence-unit>
</persistence>
This is the contents of the list. Should this be happening ?
[null, org.jboss.orm.test.entity.CustomerInventory@60bfb9a5, org.jboss.orm.test.entity.CustomerInventory@3f31a783, org.jboss.orm.test.entity.CustomerInventory@13b3a21f, org.jboss.orm.test.entity.CustomerInventory@388a91e1, org.jboss.orm.test.entity.CustomerInventory@12d67edd]
I am using 4.1.3.Final version of Hibernate. This error occurs both with PostgreSQL and MySQL.
Regards,
Jeremy