我正在尝试使用Hibernate持久保存数据,并且在运行时遇到了以下异常。
实体类
select *
from (select product, dept, (sump_1 + sump_2 + sump_3) /3 as avg_max,
row_number() over (partition by product order by (sump_1 + sump_2 + sump_3) /3 desc) as seqnum
from (select product, dept, date, sum(percentage) as sump,
lag(sum(percentage)) over (partition by product, dept order by date) as sump_1,
lag(sum(percentage, 2)) over (partition by product, dept order by date) as sump_2
from TBO_POS pos join
TBL_MV mv
on pos.IV_ID = mv.IV_ID
where Date = […] and TFC in […]
group by product, dept, date
) t
) t
where seqnum = 1;
这是import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name="FINANCES_USER")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="USER_ID")
private Long userId;
@Column(name="FIRST_NAME")
private String firstName;
@Column(name="LAST_NAME")
private String lastName;
@Column(name="BIRHT_DATE", nullable = false)
private Date birthDate;
@Column(name = "EMAIL_ADDRESS")
private String emailAddress;
@Column(name = "LAST_UPDATED_DATE")
private Date lastUpdatedDate;
@Column(name = "LAST_UPDATED_BY")
private String lastUpdatedBy;
@Column(name = "CREATED_DATE", updatable = false)
private Date createdDate;
@Column(name = "CREATED_BY",updatable = false)
private String createdBy;
:
hibernate.cfg.xml
这是我的主要内容:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/ifinances</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping class="com.codenogo.data.entities.User"/>
</session-factory>
我在 public class Application {
public static void main(String[] args){
Session session = HibernateUtil.getSessionFactory().openSession();
session.getTransaction().begin();
User user = new User();
user.setBirthDate(new Date());
user.setCreatedDate(new Date());
user.setCreatedBy("Arnold");
user.setEmailAddress("argo@mail.com");
user.setFirstName("Arod");
user.setLastName("Nogo");
user.setLastUpdatedBy("Arno");
user.setLastUpdatedDate(new Date());
session.save(user);
session.getTransaction().commit();
session.close();
}
}
课程中导入了javax.persistence.*
。尽管已将实体类映射到xml配置文件中,但我无法将数据持久保存到我的数据库中。我得到了这个例外:
Entity
对此有何帮助?
答案 0 :(得分:0)
尝试从<mapping class="com.codenogo.data.entities.User"/>
文件中删除此行:hibernate.cfg.xml
,因为您使用的是Annotations来映射您的实体而不是xml映射模式