From: <leg...@at...> - 2003-10-31 11:02:14
|
Message: A new issue has been created in JIRA. --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HBI-16 Here is an overview of the issue: --------------------------------------------------------------------- Key: HBI-16 Summary: session.find doesn't return any records while records exist in the database Type: Bug Status: Unassigned Priority: Blocker Project: Hibernate 1.2 Assignee: Reporter: Hans Keppens Created: Fri, 31 Oct 2003 5:00 AM Updated: Fri, 31 Oct 2003 5:00 AM Environment: Windows 2000 JBoss 3.2.1 + Tomcat 4.1.24 Hibernate 1.2 XDoclet for generating hibernate mapping xml files MS SQL database freeTDS driver cirrus.hibernate.sql.SybaseDialect DBCP connection pool Description: The problem is that session.find(<some query>) doesn't always return the rows I'm expecting. Apparantly, it is a timing issue, because sometimes it works fine (rows are returned), but in another run of the server, no rows are returned. The code never changes any values in the tables that are searched by session.find, so I would expect more deterministic behaviour... Some extra details: The case uses 4 classes: a class ScenarioList, a class ScenarioListData, a class LargeString and a class LargeStringPart. (LargeString and LargeStringPart are a kind of 'portable CLOB'...). Tables: SCENARIO_LIST ------------- ID: number(19) CONFIG_ID: number(19) ENTITY_NAME: varchar(50) LIST_NAME: varchar(200) SCENARIO_LIST_DATA ------------------ ID: number(19) LARGESTRING_ID: number(19) SCENARIO_LIST_ID: number(19) VIEW_NAME: varchar(200) LARGESTRING ----------- ID: number(19) LARGESTRING_TYPE: varchar(30) LARGESTRING_PART ---------------- ID: number(19) LARGESTRING_ID: number(19) PART_NUMBER: number(10) PART_VALUE: varchar(4000) These classes are linked to each other as follows (see below for the Hibernate classes). ScenarioList 1 --- * ScenarioListData ScenarioListData * --- 1 LargeString LargeString 1 --- * LargeStringPart For a given configId, entity and listName, I have a record in the database in the ScenarioList table and linked to it a record in the ScenarioListData table. Also, records in the LargeString and LargeStringPart tables exists. The following method SOMETIMES executes the code inside the "if (results.size() != 1)" block, and adds a warning to my logging: WARN direct query 1 results found, while results.size() = 0 public List getResults(long configId, String entity, String listName) throws HibernateException, SQLException { List result = session.find("from sl in class ScenarioList " + "where sl.configurationId = ? " + "and sl.entityName = ? " + "and sl.listName = ?", new Object[] { new Long(configId), entity, listName }, new NullableType[] { Hibernate.LONG, Hibernate.STRING, Hibernate.STRING }); if (result.size() != 1) { // trying direct SQL here, to prove session.find is wrong int count = 0; Connection con = session.connection(); PreparedStatement prepStat = null; ResultSet rs = null; try { prepStat = con.prepareStatement("select count(*) " + "from scenario_list " + "where config_id = ? " + "and entity_name = ? " + "and list_name = ?"); prepStat.setLong(1, configId); prepStat.setString(2, entity); prepStat.setString(3, listName); rs = prepStat.executeQuery(); if (rs.next()) { count = rs.getInt(1); } else { log.warn("direct query no count(*) data found!?"); } } finally { if (rs != null) { rs.close(); } if (prepStat != null) { prepStat.close(); } } if (count != result.size()) { log.warn("direct query " + count + " results found, while results.size() = " + result.size()); } return null; } return result; } Hibernate classes: /** * @hibernate.class table="SCENARIO_LIST" */ public class ScenarioList implements Serializable { private long id = -1; private long configurationId = -1; private String listName; private String entityName; private Set data; public ScenarioList() { } /** * @hibernate.id * column="ID" * type="long" * length="9" * unsaved-value="-1" * generator-class="data4s.pinpoint.hibernate.IdentifierGenerator" * generator-class-parameter-1="SCENARIO_LIST" */ public long getId() { return this.id; } /** * @hibernate.property * column="CONFIG_ID" * type="long" * length="9" * not-null="false" * unique="false" */ public long getConfigurationId() { return this.configurationId; } /** * @hibernate.set * role="data" * lazy="true" * cascade="delete" * --readonly="false" * --sort="natural" * --order-by="columnName" * @hibernate.collection-one-to-many * class="data4s.pinpoint.model.ScenarioListData" * @hibernate.collection-key * column="SCENARIO_LIST_ID" */ public Set getData() { return this.data; } /** * @hibernate.property * column="ENTITY_NAME" * type="java.lang.String" * length="50" * not-null="false" * unique="false" */ public String getEntityName() { return this.entityName; } /** * @hibernate.property * column="LIST_NAME" * type="java.lang.String" * length="200" * not-null="true" * unique="false" */ public String getListName() { return this.listName; } public void setConfigurationId(long configurationId) { this.configurationId = configurationId; } public void setData(Set data) { this.data = data; } public void setEntityName(String entityName) { this.entityName = entityName; } public void setId(long id) { this.id = id; } public void setListName(String listName) { this.listName = listName; } public String toString() { return "not implemented"; } public boolean equals(Object other) { if (!(other instanceof ScenarioList)) return false; ScenarioList castOther = (ScenarioList) other; return new EqualsBuilder().append(this.id, castOther.id).isEquals(); } public int hashCode() { return new HashCodeBuilder().append(id).toHashCode(); } } /** * @hibernate.class table="SCENARIO_LIST_DATA" */ public class ScenarioListData { private long id = -1; private long scenarioListId; private String viewName; private LargeString dataXml; /** * @hibernate.id * column="ID" * type="long" * length="9" * unsaved-value="-1" * generator-class="data4s.pinpoint.hibernate.IdentifierGenerator" * generator-class-parameter-1="SCENARIO_LIST_DATA" */ public long getId() { return this.id; } public void setId(long id) { this.id = id; } /** * @hibernate.property * column="SCENARIO_LIST_ID" * type="long" * length="9" * not-null="false" * unique="false" */ public long getScenarioListId() { return this.scenarioListId; } public void setScenarioListId(long scenarioListId) { this.scenarioListId = scenarioListId; } /** * @hibernate.property * column="VIEW_NAME" * type="java.lang.String" * length="200" * not-null="false" * unique="false" */ public String getViewName() { return this.viewName; } public void setViewName(String viewName) { this.viewName = viewName; } /** * @hibernate.many-to-one * column="LARGESTRING_ID" * class="data4s.pinpoint.model.LargeString" * not-null="false" * unique="false" * cascade="delete" * --outer-join="false" */ public LargeString getDataXml() { return this.dataXml; } public void setDataXml(LargeString dataXml) { this.dataXml = dataXml; } public String toString() { return "not implemented"; } public boolean equals(Object other) { if (!(other instanceof ScenarioListData)) return false; ScenarioListData castOther = (ScenarioListData) other; return new EqualsBuilder().append(this.id, castOther.id).isEquals(); } public int hashCode() { return new HashCodeBuilder().append(id).toHashCode(); } } /** * @hibernate.class table="LARGESTRING" */ public class LargeString implements Serializable { private static Log log = LogFactory.getLog(LargeString.class); private long id = -1; private String type; private Set parts; public LargeString() { } /** * @hibernate.id * column="ID" * type="long" * length="9" * unsaved-value="-1" * generator-class="data4s.pinpoint.hibernate.IdentifierGenerator" * generator-class-parameter-1="LARGESTRING" */ public long getId() { return this.id; } public void setId(long id) { this.id = id; } /** * @hibernate.property * column="LARGESTRING_TYPE" * type="java.lang.String" * length="30" * not-null="true" * unique="false" */ public java.lang.String getType() { return this.type; } public void setType(java.lang.String type) { this.type = type; } /** * @hibernate.set * role="parts" * lazy="true" * cascade="delete" * --readonly="false" * sort="natural" * --order-by="columnName" * @hibernate.collection-one-to-many * class="data4s.pinpoint.model.LargeStringPart" * @hibernate.collection-key * column="LARGESTRING_ID" */ public java.util.Set getParts() { return this.parts; } public void setParts(java.util.Set parts) { this.parts = parts; } public String toString() { return "not implemented"; } public boolean equals(Object other) { if (!(other instanceof LargeString)) return false; LargeString castOther = (LargeString) other; return new EqualsBuilder().append(this.id, castOther.id).isEquals(); } public int hashCode() { return new HashCodeBuilder().append(id).toHashCode(); } public String getValue() { if (this.parts == null) { return null; } StringBuffer buf = new StringBuffer(); for (Iterator i = this.parts.iterator(); i.hasNext(); ) { LargeStringPart part = (LargeStringPart) i.next(); buf.append(part.getValue()); } return buf.toString(); } public void setValue(Session session, long largeStringId, String value) throws HibernateException, SQLException { // delete previous parts session.delete("from lsp in class LargeStringPart where lsp.largeStringId = ?", new Long(largeStringId), Hibernate.LONG); List valueParts = StringUtil.splitIntoParts(value, 2000); for (int i = 0; i < valueParts.size(); i++) { String valuePart = (String) valueParts.get(i); LargeStringPart part = new LargeStringPart(); part.setPartNumber(i); part.setValue(valuePart); part.setLargeStringId(largeStringId); session.saveOrUpdate(part); } } } /** * @hibernate.class table="LARGESTRING_PART" */ public class LargeStringPart implements Serializable, Comparable { private long id = -1; private long largeStringId; private String value; private int partNumber; /** * @hibernate.id * column="ID" * type="long" * length="9" * unsaved-value="-1" * generator-class="data4s.pinpoint.hibernate.IdentifierGenerator" * generator-class-parameter-1="LARGESTRING_PART" */ public long getId() { return this.id; } public void setId(long id) { this.id = id; } /** * @hibernate.property * column="LARGESTRING_ID" * type="long" * length="9" * not-null="false" * unique="false" */ public long getLargeStringId() { return this.largeStringId; } public void setLargeStringId(long largeStringId) { this.largeStringId = largeStringId; } /** * @hibernate.property * column="PART_VALUE" * type="java.lang.String" * length="4000" * not-null="false" * unique="false" */ public String getValue() { return this.value; } public void setValue(String value) { this.value = value; } /** * @hibernate.property * column="PART_NUMBER" * type="int" * not-null="false" * unique="false" */ public int getPartNumber() { return this.partNumber; } public void setPartNumber(int partNumber) { this.partNumber = partNumber; } public String toString() { return "not implemented"; } public boolean equals(Object other) { if (!(other instanceof LargeStringPart)) return false; LargeStringPart castOther = (LargeStringPart) other; return new EqualsBuilder().append(this.id, castOther.id).isEquals(); } public int hashCode() { return new HashCodeBuilder().append(id).toHashCode(); } public int compareTo(Object other) { if (!(other instanceof LargeStringPart)) return -1; LargeStringPart castOther = (LargeStringPart) other; if (getPartNumber() < castOther.getPartNumber()) return -1; else if (getPartNumber() > castOther.getPartNumber()) return 1; return 0; } } Is this a known issue with 1.2? Regards, Hans --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |