-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using where attribute in class tag
PostPosted: Tue Nov 25, 2003 12:35 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
There where clause in my <class> tag is not being added to the query executed when selecting form my table. Is this a bug or am I not using the "where" property correctly.

I have created a simple test program to demonstrate my problem.

Running on WinXp Sun JVM 1.4.1_5.

Here is the program output:

- Hibernate 2.0.3
- hibernate.properties not found
- using CGLIB reflection optimizer
- JVM proxy support: true
- Mapping resource: capa/hibernate/AfTest.hbm.xml
- Mapping class: capa.hibernate.AfTest -> AF_TEST
- processing one-to-many association mappings
- processing foreign key constraints
- building session factory
- Using dialect: net.sf.hibernate.dialect.SybaseDialect
- No connection properties specified - the user must supply JDBC connections
- Use outer join fetching: true
- Use scrollable result sets: false
- echoing all SQL to stdout
- no JDNI name configured
- Query language substitutions: {}
Hibernate: select aftest0_.PK_VALUE as PK_VALUE, aftest0_.DATA as DATA, aftest0_.version as version, aftest0_.current_version as current_4_ from AF_TEST aftest0_ where aftest0_.PK_VALUE=?
net.sf.hibernate.HibernateException: More than one row with the given identifier was found: 1, for class: capa.hibernate.AfTest
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:50)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
at capa.hibernate.AfTest.main(AfTest.java:74)
Process terminated with exit code 0

Here is my hbm file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="capa.hibernate.AfTest"
table="AF_TEST"
where="current_version=1"
>
<id
name="pkValue"
type="java.lang.Integer"
column="PK_VALUE"
unsaved-value="null"
>
<generator class="assigned"/>
</id>
<property
name="data"
type="java.lang.String"
column="DATA"
length="10"
>
</property>
<property
name="version"
type="java.lang.Integer"
column="version"
length="9"
>
</property>
<property
name="currentVersion"
type="java.lang.Integer"
column="current_version"
length="9"
>
</property>
</class>
</hibernate-mapping>


Here is the AfTest test file that is both the persistent class and the test program.

package capa.hibernate;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;

import java.sql.Connection;
import java.sql.DriverManager;

public class AfTest
{
private Integer pkValue;
private String data;
private Integer version;
private Integer currentVersion;

public Integer getPkValue()
{
return pkValue;
}

public void setPkValue(Integer pkValue)
{
this.pkValue = pkValue;
}

public String getData()
{
return data;
}

public void setData(String data)
{
this.data = data;
}

public Integer getVersion()
{
return version;
}

public void setVersion(Integer version)
{
this.version = version;
}

public Integer getCurrentVersion()
{
return currentVersion;
}

public void setCurrentVersion(Integer currentVersion)
{
this.currentVersion = currentVersion;
}

public static void main(String[] args)
{
try
{
Class.forName("com.jnetdirect.jsql.JSQLDriver");
Connection conn = DriverManager.getConnection("jdbc:JSQLConnect://netregulus12:1124/database=pqi_dev_63", args[0], args[1]);

Configuration cfg = (new Configuration())
.addClass(capa.hibernate.AfTest.class);

cfg.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.SybaseDialect");
cfg.setProperty("hibernate.show_sql", "true");

SessionFactory capaSessionFactory = cfg.buildSessionFactory();
Session sess = capaSessionFactory.openSession(conn);
net.sf.hibernate.Transaction tx = sess.beginTransaction();

AfTest test = (AfTest) sess.load(capa.hibernate.AfTest.class, new Integer(1));
System.out.println("test.getData()[" + test.getData() + "]");
tx.commit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Here is the SQL Script to create the table and test data in SqlServer:

create table af_test
(
pk_value int,
data varchar(10),
version int,
current_version int
)

create unique index pk_af_test on af_test (pk_value, version)

insert into af_test values
(1, 'one', 1, 0)

insert into af_test values
(1, 'two', 2, 0)

insert into af_test values
(1, 'three', 3, 0)

insert into af_test values
(1, 'four', 4, 1)

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
this is expected


Top
 Profile  
 
 Post subject: Using where attribute in class tag
PostPosted: Tue Nov 25, 2003 12:41 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
gavin wrote:
this is expected


When would the "where" attribute be added to the select query?
What is the propert usage?

_________________
Arthur Fitt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.