标签:无法 birt 不同 key JD 而且 show ESS sts
标注用于实体类声明语句之前,指出该Java类为实体类,将映射到指定的数据库表。如声明一个实体类Customer,将它映射到数据的coustomer表上。
package com.dxsoft.jpa.helloword; import javax.persistence.Entity; @Entity public class Person { //... }
package com.dxsoft.jpa.helloword; import javax.persistence.Entity; import javax.persistence.Table; @Entity @Table(name = "jpa_person") public class Person { //。。。 }
假设Person类需要扩展一个帮助方法,getUserInfo()
// 帮助方法,不希望保存到数据库,但是需要动态获取Customer对象的属性。 public String getUserInfo() { return "username:" + fullName + ",age:" + age; }
此时,运行时抛出异常。
解决上边需求,而且又不抛异常的方案:需要在getUserInfo()方法上添加注解@Transient
修改项目:
1)修改Person实体类,新增birth,createTime字段
package com.dxsoft.jpa.helloword; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; @Entity @Table(name = "jpa_person") public class Person { private Integer id; private String fullName; private int age; private Date birth; private Date createTime; public Person() { } @GeneratedValue(strategy = GenerationType.AUTO) @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Column(name = "full_name", nullable = false, length = 64) public String getFullName() { return fullName; } public void setFullName(String fullName) { this.fullName = fullName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Date getBirth() { return birth; } public void setBirth(Date birth) { this.birth = birth; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } // 帮助方法,不希望保存到数据库,但是需要动态获取Customer对象的属性。 @Transient public String getUserInfo() { return "username:" + fullName + ",age:" + age; } @Override public String toString() { return "Person [id=" + id + ", fullName=" + fullName + ", age=" + age + "]"; } }
2)修改测试main函数
此时,删除mysql数据中的jpa_person表,重新运行。
运行日志:
Hibernate: create table hibernate_sequence ( next_val bigint ) engine=InnoDB Hibernate: insert into hibernate_sequence values ( 1 ) Hibernate: create table jpa_person ( id integer not null, age integer not null, birth datetime, createTime datetime, full_name varchar(64) not null, primary key (id) ) engine=InnoDB Fri Jun 15 12:25:35 CST 2018 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Hibernate: select next_val as id_val from hibernate_sequence for update Hibernate: update hibernate_sequence set next_val= ? where next_val=? Hibernate: insert into jpa_person (age, birth, createTime, full_name, id) values (?, ?, ?, ?, ?) 六月 15, 2018 12:25:35 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://127.0.0.1:3306/jpa] complete..
此时查看mysql中表
显然这里的createTime可以使用,但是birth的日期精度要求是短日期格式就可以。
使用@Temporal注解来调整Date精度
修改person.java实体类
删除mysql中数据库jpa_person表,重新运行查看数据表结构,及数据。
运行日志:
Hibernate: create table hibernate_sequence ( next_val bigint ) engine=InnoDB Hibernate: insert into hibernate_sequence values ( 1 ) Hibernate: create table jpa_person ( id integer not null, age integer not null, birth date, createTime datetime, full_name varchar(64) not null, primary key (id) ) engine=InnoDB Fri Jun 15 12:30:16 CST 2018 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Hibernate: select next_val as id_val from hibernate_sequence for update Hibernate: update hibernate_sequence set next_val= ? where next_val=? Hibernate: insert into jpa_person (age, birth, createTime, full_name, id) values (?, ?, ?, ?, ?) 六月 15, 2018 12:30:16 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://127.0.0.1:3306/jpa] complete..
标签:无法 birt 不同 key JD 而且 show ESS sts
原文地址:https://www.cnblogs.com/yy3b2007com/p/9186698.html