[color=blue]Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version:[/b] 2.03
[b]Mapping documents:[/b]
<?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="com.inetmon.jn.addrbook.Address" table="ADDRBOOK">
<id name="MAC" type="java.lang.String" unsaved-value="null" >
<column name="MAC" sql-type="String"
not-null="false"/>
<generator class="assigned"/>
</id>
<property name="IPv4" column="IPv4" type="java.lang.String" />
<property name="IPv6" column="IPv6" type="java.lang.String"/>
</class>
</hibernate-mapping>
[b]Code between sessionFactory.openSession() and session.close():[/b]
try {
// get the session from the factory
session = HibernateSessionFactory.currentSession();
//always start a transaction before doing something
// (even reading) from the database
tx = session.beginTransaction();
List s =session.find("select * from ADDRBOOK");
//Query q = session.createQuery("Select MAC from ADDRBOOK");
//System.out.println("111");
//List s = session.find("select * from NETWORK");
//List s = session.find("SELECT * from Addrbook ");
System.out.println("111");
for (Iterator iter = s.iterator(); iter.hasNext();) {
Address addr = (Address) iter.next();
System.out.println("[MAC] " + addr.getMAC() + " [IPv4] "
+ addr.getIPv4()+ " [IPv6] " +addr.getIPv6());
}
// commit your transaction or nothing is wrote to the db
tx.commit();
// clean up (close the session)
session.close();
} catch (HibernateException e) {
// [laliluna] when an error occured, try to rollback your
// transaction
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1) {
log.warn("rollback not successful");
}
/*
* [laliluna] close your session after an exception!! Your session
* is in an undefined and unstable situation so throw it away!
*
*/
if (session != null)
try {
session.close();
} catch (HibernateException e2) {
log.warn("session close not successful");
}
}
[b]Full stack trace of any exception that occurs:[/b]
[b]Name and version of the database you are using:[/b]
HSQLDB 1.7.3
[b]The generated SQL (show_sql=true):[/b]
CREATE TABLE ADDRBOOK(MAC VARCHAR NOT NULL PRIMARY KEY,IPV4 VARCHAR NOT NULL,IPV6 VARCHAR NOT NULL)
CREATE USER SA PASSWORD "" ADMIN
SET WRITE_DELAY 60
INSERT INTO ADDRBOOK VALUES('LK-FF-33-KL-TR-44','100.25.5.25','100.128.24.45')
INSERT INTO ADDRBOOK VALUES('LM-55-88-K2-TR-44','100.25.5.25','100.128.24.45')
INSERT INTO ADDRBOOK VALUES('OP-FF-33-88-LK-44','100.25.5.25','100.128.24.45')
INSERT INTO ADDRBOOK VALUES('OP-FF-33-KL-TR-44','100.25.5.25','100.128.24.45')
[b]Debug level Hibernate log excerpt:[/b]
Problem : After execute it, i cannot see the output. anyone know how to use session.find () . session.delete() ,session.createQuery .What is the difference between these three? Thanks you.[color=darkred][/color][color=blue][/color][/color]