当然,我使用 Hibernate 框架编写了一个算法来浏览表并返回多行。
但是,此算法会擦除表的内容,然后此 Query 的返回为null。
ArrayList<Compte> list = null;
try {
Session session = HibernateUtils.getSession();
Transaction tx = session.beginTransaction();
Query q = s.createQuery("from Compte where compte_utilisateuridentifiant = :y");
q.setString("y", identifiant);
list = (ArrayList<Compte>) q.list();
tx.commit();
} catch (HibernateException e) {
} finally {
}
for (Compte c: list)
System.out.println("[rib] = " + c.getRib() + "\t" +
"[title] = " + c.getLibelle() + "\t" +
"[dateC] = " + c.getDateCréation() + "\t");
return list;
这是CFG文件:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Paramètres de connexion à la base de données -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/bh</property>
<property name="connection.username">postgres</property>
<property name="connection.password">esct</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Comportement pour la conservation des tables -->
<property name="hbm2ddl.auto">create</property>
<!-- Activation : affichage en console, commentées et formatées -->
<property name="show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="use_sql_comments">true</property>
<!-- Fichiers à mapper -->
<mapping class="tn.bh.jpa.Compte" />
<mapping class="tn.bh.jpa.Mouvement_Compte" />
<mapping class="tn.bh.jpa.Solde" />
<mapping class="tn.bh.jpa.User" />
<mapping class="tn.bh.jpa.Virement" />
有人能帮助我吗 ?谢谢 :)