我有:(MySQL 5.1)
CREATE TABLE `poh_faktury` (
`cislo` int(10) unsigned NOT NULL PRIMARY KEY,
...
) ENGINE=MyISAM DEFAULT CHARSET=utf8$$
@Entity
@Table(name="poh_faktury")
@NamedQueries({
@NamedQuery(name="dalsiCisloFaktury", query="SELECT MAX(fakt.cislo) + 1 FROM Faktura AS fakt")
})
生成的查询(是的,两个)是:
select MAX(faktura0_.cislo)+1 as col_0_0_ from poh_faktury faktura0_
select MAX(faktura0_.cislo)+1 as col_0_0_ from poh_faktury faktura0_ limit 2
但是这个
Integer res = ((Integer) this.getJpaTemplate().execute( new JpaCallback() {
public Object doInJpa( EntityManager em ) throws PersistenceException {
Query q = em.createNamedQuery( "dalsiCisloFaktury" );
return q.getSingleResult();
}
}));
放入. null
_res
当我调用 SQL 时,它应该返回 1000:
SELECT MAX(fakt.cislo) + 1 FROM poh_faktury AS fakt;
我应该如何让 Hibernate 返回正确的标量值?