When i run the code below (sorry for the long post), i get an infinite loop, with the same select being executed over an over. Thanx for any help
Hibernate version:
2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="simple.EE"
table="ee"
>
<id
name="uuid"
type="simple.MutableByteType"
column="uuid"
unsaved-value="null"
>
<generator class="assigned" />
</id>
<many-to-one
name="parent"
class="simple.EE"
cascade="none"
>
<column name="parent_uuid" not-null="false"/>
</many-to-one>
<set name="children"
cascade="all-delete-orphan"
inverse="true"
lazy="false"
batch-size="10"
>
<key column="parent_uuid"/>
<one-to-many class="simple.EE"/>
</set>
<property
name="value"
column="value"
type="string"
/>
</class>
Code between sessionFactory.openSession() and session.close():
EE it = (EE)s.get(EE.class, new MutableByte(new byte[] {
(byte) 1, (byte) 7, (byte) 7, (byte) 7 }));
System.out.println(it.getChildren().size());
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
Ingres r3.0
The generated SQL (show_sql=true):
lots of selects
Debug level Hibernate log excerpt:
I'm trying to follow directions from
http://www.hibernate.org/50.html. The class looks as follows:
package simple;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/** @author Hibernate CodeGenerator */
public class EE implements Serializable {
/** identifier field */
private MutableByteVarying uuid;
private EE parent;
private Set children;
private String value;
/** full constructor */
public EE(MutableByteVarying uuid) {
this.uuid = uuid;
}
public EE(MutableByteVarying uuid, EE parent, String value) {
this();
this.uuid = uuid;
this.parent = parent;
this.value = value;
}
/** default constructor */
public EE() {
children = new HashSet();
}
public MutableByteVarying getUuid() {
return this.uuid;
}
public void setUuid(MutableByteVarying binary) {
this.uuid = binary;
}
public EE getParent() {
return parent;
}
public void setParent(EE parent) {
this.parent = parent;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Set getChildren() {
return children;
}
private void setChildren(Set children) {
this.children = children;
}
public void addChild(EE child) {
if(child == null){
throw new IllegalArgumentException("Null is not a valid EE");
}
if (child.getParent() != null) {
child.getParent().getChildren().remove(child);
}
child.setParent(this);
children.add(child);
}
}
The types are:
package simple;
import java.io.Serializable;
import java.util.Arrays;
import net.sf.hibernate.type.MutableType;
public final class MutableByte implements Serializable {
private byte[] _bytes;
public MutableByteVarying(byte[] bytes) {
_bytes = bytes;
}
public boolean equals(Object other) {
// System.out.println("MutableByteVarying::equals: " + other);
if (other == null || !(other instanceof MutableByteVarying)){
// System.out.println("false");
return false;
}
System.out.println(Arrays.equals(((MutableByte) other)._bytes, _bytes));
return Arrays.equals(((MutableByteVarying) other)._bytes, _bytes);
}
public byte[] getBytes() {
System.out.println("MutableByteVarying::getBytes: " + toHex(_bytes));
if (_bytes == null) {
return null;
}
byte[] clone = new byte[_bytes.length];
System.arraycopy(_bytes, 0, clone, 0, _bytes.length);
return clone;
}
}
/*
* Created on Nov 5, 2004
*
* TODO To change the template for this generated file go to Window -
* Preferences - Java - Code Style - Code Templates
*/
package simple;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.UserType;
import net.sf.hibernate.type.MutableType;
public class MutableByteType extends MutableType implements Serializable {
public boolean equals(Object x, Object y) {
return (x == y) || (x != null && y != null && x.equals(y));
}
public Object get(ResultSet rs, String name) throws HibernateException,
SQLException {
return new MutableByteVarying(rs.getBytes(name));
}
public void set(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
st.setBytes(index, ((MutableByteVarying) value).getBytes());
}
public int sqlType() {
return Types.VARBINARY;
}
public String toString(Object value) throws HibernateException {
byte[] bytes = ((MutableByteVarying) value).getBytes();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
String hexStr = Integer.toHexString(bytes[i] - Byte.MIN_VALUE);
if (hexStr.length() == 1)
buf.append('0');
buf.append(hexStr);
}
return buf.toString();
}
public Object fromStringValue(String xml) throws HibernateException {
if (xml == null)
return null;
if (xml.length() % 2 != 0)
throw new IllegalArgumentException(
"The string is not a valid xml representation of a binary content.");
byte[] bytes = new byte[xml.length() / 2];
for (int i = 0; i < bytes.length; i++) {
String hexStr = xml.substring(i * 2, (i + 1) * 2);
bytes[i] = (byte) (Integer.parseInt(hexStr, 16) + Byte.MIN_VALUE);
}
return new MutableByte(bytes);
}
public Object deepCopyNotNull(Object value) throws HibernateException {
byte[] bytes = ((MutableByte) value).getBytes();
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}
public Class getReturnedClass() {
return MutableByteVarying.class;
}
public String getName() {
return "mutable byte";
}
}