- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 JPA 和 hibernate 的初学者,我只是想通过 hibernate 从我的数据库中获取一些数据,但我失败了,我收到了这个错误:
Apr 29, 2019 5:14:28 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing qPersistenceUnitInfo [name: NewPersistenceUnit]
Apr 29, 2019 5:14:29 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.4.2.Final}
Apr 29, 2019 5:14:29 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Apr 29, 2019 5:14:30 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Apr 29, 2019 5:14:30 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/shopping]
Apr 29, 2019 5:14:30 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Apr 29, 2019 5:14:30 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Apr 29, 2019 5:14:30 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Apr 29, 2019 5:14:32 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
Apr 29, 2019 5:14:33 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@35e478f] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Apr 29, 2019 5:14:33 AM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Hibernate:
select
itemclass0_.id as id1_0_0_,
itemclass0_.author as author2_0_0_,
itemclass0_.available_amount as availabl3_0_0_,
itemclass0_.bought as bought4_0_0_,
itemclass0_.imageURL as imageURL5_0_0_,
itemclass0_.name as name6_0_0_,
itemclass0_.price as price7_0_0_,
itemclass0_.publish_time as publish_8_0_0_
from
item itemclass0_
where
itemclass0_.id=?
Apr 29, 2019 5:14:33 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: S1009
Apr 29, 2019 5:14:33 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: MONTH
Apr 29, 2019 5:14:33 AM org.hibernate.event.internal.DefaultLoadEventListener doOnLoad
INFO: HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : EntityKey[entities.ItemClass#58]
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : EntityKey[entities.ItemClass#58]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3581)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3519)
at Test.main(Test.java:17)
Caused by: org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : EntityKey[entities.ItemClass#58]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:320)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateEntityState(EntityReferenceInitializerImpl.java:233)
at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:103)
at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:254)
at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:197)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4279)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:482)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:452)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:203)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:105)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1287)
at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:212)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2930)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2911)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2867)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2911)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3552)
... 2 more
Caused by: java.sql.SQLException: MONTH
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:85)
at com.mysql.cj.jdbc.result.ResultSetImpl.getDate(ResultSetImpl.java:847)
at com.mysql.cj.jdbc.result.ResultSetImpl.getDate(ResultSetImpl.java:860)
at org.hibernate.type.descriptor.sql.DateTypeDescriptor$2.doExtract(DateTypeDescriptor.java:76)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3014)
at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:305)
... 23 more
Caused by: com.mysql.cj.exceptions.WrongArgumentException: MONTH
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
at com.mysql.cj.result.SqlDateValueFactory.createFromDate(SqlDateValueFactory.java:80)
at com.mysql.cj.result.SqlDateValueFactory.createFromDate(SqlDateValueFactory.java:46)
at com.mysql.cj.result.BaseDecoratingValueFactory.createFromDate(BaseDecoratingValueFactory.java:53)
at com.mysql.cj.result.BaseDecoratingValueFactory.createFromDate(BaseDecoratingValueFactory.java:53)
at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeDate(MysqlTextValueDecoder.java:72)
at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:90)
at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:250)
at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91)
at com.mysql.cj.jdbc.result.ResultSetImpl.getNonStringValueFromRow(ResultSetImpl.java:656)
at com.mysql.cj.jdbc.result.ResultSetImpl.getDateOrTimestampValueFromRow(ResultSetImpl.java:679)
... 33 more
Caused by: java.lang.IllegalArgumentException: MONTH
at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2648)
at java.util.Calendar.updateTime(Calendar.java:3393)
at java.util.Calendar.getTimeInMillis(Calendar.java:1782)
at com.mysql.cj.result.SqlDateValueFactory.createFromDate(SqlDateValueFactory.java:77)
... 42 more
Process finished with exit code 1
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>entities.ItemClass</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/shopping"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="expectopatronum"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
package entities;
import javax.persistence.*;
import java.sql.Date;
import java.util.Objects;
@Entity
@Table(name = "item", schema = "shopping", catalog = "")
public class ItemClass {
private int id;
private String name;
private Integer price;
private String imageUrl;
private Integer availableAmount;
private Integer bought;
@Temporal(TemporalType.TIMESTAMP)
private Date publishTime;
private String author;
@Id
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "name", nullable = false, length = 45)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "price", nullable = true)
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
@Basic
@Column(name = "imageURL", nullable = true, length = 45)
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
@Basic
@Column(name = "available_amount", nullable = true)
public Integer getAvailableAmount() {
return availableAmount;
}
public void setAvailableAmount(Integer availableAmount) {
this.availableAmount = availableAmount;
}
@Basic
@Column(name = "bought", nullable = true)
public Integer getBought() {
return bought;
}
public void setBought(Integer bought) {
this.bought = bought;
}
@Basic
@Column(name = "publish_time", nullable = true)
public Date getPublishTime() {
return publishTime;
}
public void setPublishTime(Date publishTime) {
this.publishTime = publishTime;
}
@Basic
@Column(name = "author", nullable = false, length = 45)
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ItemClass itemClass = (ItemClass) o;
return id == itemClass.id &&
Objects.equals(name, itemClass.name) &&
Objects.equals(price, itemClass.price) &&
Objects.equals(imageUrl, itemClass.imageUrl) &&
Objects.equals(availableAmount, itemClass.availableAmount) &&
Objects.equals(bought, itemClass.bought) &&
Objects.equals(publishTime, itemClass.publishTime) &&
Objects.equals(author, itemClass.author);
}
@Override
public int hashCode() {
return Objects.hash(id, name, price, imageUrl, availableAmount, bought, publishTime, author);
}
}
import entities.ItemClass;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class Test {
public static void main(String[] args) {
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("NewPersistenceUnit");
EntityManager entityManager = entityManagerFactory.createEntityManager();
ItemClass item = entityManager.find(ItemClass.class,58);
System.out.println(item.getAuthor());
}
}
最佳答案
这可能是数据问题(在数据库表中)。
mysql 表可以包含日期时间/时间戳条目,如 2019-00-00
.虽然这些日期在 mysql 中是有效的(取决于服务器版本和模式),但当 mysql 驱动程序尝试将它们解析为 Java 日期时,它们将导致异常。
仔细检查您尝试检索的行在 publish_time
中是否具有有效日期。柱子。
附:如果您的日期全部为零( 0000-00-00 00:00:00
),那么您可以使用 zeroDateTimeBehavior
连接字符串中的属性,以便在不更改数据库值的情况下更优雅地处理它们。
关于java - hibernate :无法从 ResultSet 和 IllegalArgumentException:GregorianCalendar.computeTime 读取实体状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55895887/
我正在使用 CMIS 和 Java,我从文档加载所有属性并将它们写入 xml 文件。 我使用 Object.toString() 方法在 xml 文件中创建文本节点。因此我使用 .toString()
对于以下代码片段 GregorianCalendar a = new GregorianCalendar(2009, 11, 10); System.out.println(a.getTime());
我在一个文本文件中有以下数据,稍后我将扫描该文件。 17-Mar-2006 1100 1280 16-Jan-2002 1120 1230 15-Jun-2003 1140 1900 我正在将此数据构
这个问题已经有答案了: "EEE MMM dd HH:mm:ss ZZZ yyyy" date format to java.sql.Date (2 个回答) 已关闭 4 年前。 我是 Java 新手
我在使用 GregorianCalendar 时遇到问题,因此请您帮我解决一下。首先我会给你我的代码: private String changeClock(String day, String cl
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎偏离主题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或 include a mini
这个问题已经有答案了: why do I get wrong month when parsing with java calendar (3 个回答) 已关闭5 年前。 我有下面的代码,我试图在其中
好的。 calendar.get(Calendar.MONTH); 返回当前月份的索引。例如,如果现在执行这行代码,它将返回 August 的 7。 但是 calendar.get(Calendar.
当我像这样使用 GregorianCalendar 实例化新日期时: GregorianCalendar myCal = new GregorianCalendar(29,5,2011); 然后,最后
java 6.0 假设今天是:2018 年 8 月 8 日 此处方法返回 2 个日期的月差。 public static Integer getDiffMonths(Date dateFrom
我在 Java 中使用 GregorianCalendar 类时遇到问题。为什么 get 方法会更改我的 GregorianCalendar 类型的变量? 我从事这项工作: System.out.pr
我尝试将字符串转换为 GregorianCalendar,然后检查它。下面,我发布我的代码。我真的很困惑为什么字段看起来不对。非常感谢您的帮助。 public class test{ priv
java.util.GregorianCalendar 是轻量级对象吗?换句话说,在 Web 应用程序设置中使用每个请求调用构造函数只会带来微不足道的性能损失,还是缓存对象的副本以供应用程序共享使用是
我的程序中有这段代码: if (expire.after(start) && expire.before(end)) //do somethig 但是这段代码不包含绑定(bind)日期。我的意
这个问题已经有答案了: How to sanity check a date in Java (25 个回答) 已关闭 7 年前。 GregorianCalendar构造函数有签名: Gregoria
我想计算一年中特定周数的星期一。我是这样做的: final GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); ca
出现此错误,JSP 页面变为空白(白色): Jan 9, 2013 7:30:39 PM org.apache.catalina.loader.WebappClassLoader clearThrea
我正在尝试设置 HOUR_OF_DAY 字段并更改 GregorianCalendar 日期对象的时区。 GregorianCalendar date = new GregorianCalendar(
虽然我阅读了很多关于日历和公历的内容,但仍然会出现一些复杂情况。哪个更好或者您可以推荐使用什么?我无法弄清楚其中的区别。 GregorianCalendar gc = (GregorianCalend
TimeZone utcTimezone_ = TimeZone.getTimeZone("UTC"); TimeZone _utc = TimeZone.getTimeZone("Zulu"); D
我是一名优秀的程序员,十分优秀!