我正在使用JPA和Hibernate EntityManager连接到MySQL数据库。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TaraTicketEJB">
<jta-data-source>java:jboss/datasources/TaraTicketDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
以下是服务方法:
@Stateless
@Remote(TicketDAO.class)
public class TicketBean implements TicketDAO{
@PersistenceContext
private EntityManager em;
...
@Override
public List<Ticket> getAllTickets() {
return em.createNamedQuery(Ticket.QUERY_GETALL,Ticket.class).getResultList();
}
}
这是实体:
@Entity
@NamedQuery(name=Ticket.QUERY_GETALL,query = "SELECT c FROM Ticket c")
public class Ticket implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public static final String QUERY_GETALL = "Ticket.GetAll";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotNull
@Size(min=10,max=150)
private String name;
private String description;
private String username;
private Date date;
...more properties
@Version
private Timestamp lastChanged;
...getter and setter ;)
}
我在日志中看到一条警告“SQL Error:0,SQLState:08003”。
20:16:15,594 INFO [stdout] (default task-33) Hibernate: select ticket0_.id as id1_0_, ticket0_.category as category2_0_, ticket0_.date as date3_0_, ticket0_.description as descript4_0_, ticket0_.email as email5_0_, ticket0_.lastChanged as lastChan6_0_, ticket0_.name as name7_0_, ticket0_.priority as priority8_0_, ticket0_.status as status9_0_, ticket0_.subject as subject10_0_, ticket0_.telephoneNumber as telepho11_0_, ticket0_.user as user12_0_, ticket0_.username as usernam13_0_ from Ticket ticket0_
20:16:15,596 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-33) SQL Error: 0, SQLState: 08003
这是什么意思?