-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: infinite loop using customer user type
PostPosted: Wed Nov 17, 2004 5:54 pm 
Beginner
Beginner

Joined: Thu Oct 14, 2004 9:50 am
Posts: 43
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";
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 6:03 pm 
Beginner
Beginner

Joined: Thu Oct 14, 2004 9:50 am
Posts: 43
The sql generated goes something like:
17:02:37,874 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,044 DEBUG SQL:226 - select children0_.parent_uuid as parent_u2___, children0_.uuid as uuid__, children0_.uuid as uuid0_, children0_.parent_uuid as parent_u2_0_, children0_.value as value0_ from ee children0_ where children0_.parent_uuid=?
17:02:38,064 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,084 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,104 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,134 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,144 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,154 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,175 DEBUG SQL:226 - select children0_.parent_uuid as parent_u2___, children0_.uuid as uuid__, children0_.uuid as uuid0_, children0_.parent_uuid as parent_u2_0_, children0_.value as value0_ from ee children0_ where ((children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?))
17:02:38,185 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,205 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,255 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,265 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,295 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,305 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,315 DEBUG SQL:226 - select children0_.parent_uuid as parent_u2___, children0_.uuid as uuid__, children0_.uuid as uuid0_, children0_.parent_uuid as parent_u2_0_, children0_.value as value0_ from ee children0_ where ((children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?))
17:02:38,365 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,375 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,395 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,405 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,425 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,445 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,485 DEBUG SQL:226 - select children0_.parent_uuid as parent_u2___, children0_.uuid as uuid__, children0_.uuid as uuid0_, children0_.parent_uuid as parent_u2_0_, children0_.value as value0_ from ee children0_ where ((children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?) or (children0_.parent_uuid=?))
17:02:38,495 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,515 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,525 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,535 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,545 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?
17:02:38,565 DEBUG SQL:226 - select ee0_.uuid as uuid1_, ee0_.parent_uuid as parent_u2_1_, ee0_.value as value1_, ee1_.uuid as uuid0_, ee1_.parent_uuid as parent_u2_0_, ee1_.value as value0_ from ee ee0_ left outer join ee ee1_ on ee0_.parent_uuid=ee1_.uuid where ee0_.uuid=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 10:17 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 9:50 am
Posts: 43
Please.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 11:30 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 9:50 am
Posts: 43
For anyone interested, the problem was that my mutablebyte was overiding equals without overriding hashcode.. (yes, i know).
after overriding hashcode, everything started working as expected.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.