Tag: mysql

LocalDateforms

我有一个关于Spring + Thymeleaf日期格式的问题。 我有一个带有LocalDate date字段的简单实体。 我希望从表单中的用户获取此日期并将其保存到MySQL数据库。 我收到这样的错误: 无法将类型为java.lang.String的属性值转换为属性日期所需的类型java.time.LocalDate; 嵌套exception是org.springframework.core.convert.ConversionFailedException:无法从类型java.lang.String转换为类型java.time.LocalDate,值为2019-04-30; 嵌套exception是java.time.format.DateTimeParseException:无法在索引2处解析文本2019-04-30 我的实体: @Entity @Table(name=”game”) public class Game{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Transient private User gameOwner; private LocalDate date; private LocalTime time; //other fields Thymeleaf观点/forms: Date: 这个问题的原因是什么? 也许还有其他更好的存储日期方式?

如何编写HQL插入查询?

我正在努力编写一个HQL查询来在表中插入新记录。 我已经看到了一些插入查询,如下所示,但我不希望从另一个表插入数据,如下面的代码。 String hql = “INSERT INTO Employee(firstName, lastName, salary)” + “SELECT firstName, lastName, salary FROM old_employee”; Query query = session.createQuery(hql); int result = query.executeUpdate(); System.out.println(“Rows affected: ” + result); 例如,我有一个表“User”,有三个字段,如姓名,年龄,数字,我有这个用户表的实体。 什么是插入查询?

c3p0说 – “java.lang.Exception:DEBUG ONLY:过期资源检出堆栈跟踪”启动一个hibernate事务

最近,我的tomcat开始挂起。 这些请求从未得到回复。 我发现这是因为连接永远不会返回到连接池。 我使用了c3p0和hibernate,数据库是mysql 5.5 为了调试连接泄漏,我在hibernate.cfg.xml添加了以下属性 30 true 添加后,在日志中说: [2013-10-12 23:40:22.487] [ INFO] BasicResourcePool.removeResource:1392 – A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@1f0c0dd [2013-10-12 23:40:22.487] [ INFO] BasicResourcePool.removeResource:1395 – Logging the stack trace by which the overdue resource was checked-out. java.lang.Exception: DEBUG ONLY: Overdue resource check-out stack trace. 指向at dao.DAOBasicInfo.getBean(DAOBasicInfo.java:69) public static Basicinfo […]

Java SE上的JPA:对象:entity.Customer@5e80188f不是已知的实体类型

我跟着 https://glassfish.java.net/javaee5/persistence/persistence-example.html 在Java SE环境中测试JPA。 在Eclipse中,我: 创建了一个新的JPA(2.1)项目; 在options-> JPA-> Persistent class management中,我选择了“自动发现带注释的类”而不是“必须在persistence.xml中列出带注释的类”。 我成功导入了zip文件(Client.java Customer.java Order.java)中的树Java类,并修改了persistence.xml文件以满足我的需要。 但是在尝试执行main时我得到以下错误。 [EL Info]: 2013-10-18 17:37:54.749–ServerSession(263489307)–EclipseLink, version: Eclipse Persistence Services – 2.5.1.v20130918-f2b9fc5 [EL Info]: connection: 2013-10-18 17:37:55.34–ServerSession(263489307)–file:/home/caterpillar/workspace/JPA_Java_SE/build/classes/_JPA_Java_SE login successful [EL Warning]: metamodel: 2013-10-18 17:37:55.359–The collection of metamodel types is empty. Model classes may not have been found during entity search for Java […]

无法通过reflection设置器设置字段值

在使用hibernate和MySQL的spring mvc应用程序中,我收到一个错误,这似乎表明Name实体无法找到Patient实体的BaseEntity超类的id属性的setter。 我该如何解决这个错误? 这是错误消息: Caused by: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of myapp.mypackage.Name.patient 以下是触发错误的代码行: ArrayList names = (ArrayList) this.clinicService.findNamesByPatientID(patntId); 这是BaseEntity ,它是Patient和Name的超类: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @DiscriminatorFormula(“(CASE WHEN dtype IS NULL THEN ‘BaseEntity’ ELSE dtype END)”) public class BaseEntity { @Transient private String dtype = this.getClass().getSimpleName(); @Id @GeneratedValue(strategy = GenerationType.TABLE) protected […]

更新单个表的多行

我需要更新具有超过60k行的表的每一行。 目前我这样做 – public void updateRank(Map map){ Iterator<Entry> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); String query = “update profile set rank = “+ pairs.getValue()+ ” where profileId = “+pairs.getKey(); DBUtil.update(query); it.remove(); } } 单独使用此方法需要大约20分钟才能完成,每行(60k)命中数据库就是我认为的原因。(虽然我使用dbcp进行连接池,最多有50个活动连接) 如果我能够使用单个数据库命中更新行,那就太棒了。 那可能吗 ? 怎么样 ? 或者其他任何改善时间的方法?

Spring-Hibernate使用多个数据源/数据库

我正在使用一个使用Spring MVC 3和Hibernate的Web应用程序 我想为我的Web应用程序使用2个数据源MySql和Oracle数据库, 我已经阅读了许多关于“spring-hibernate multiple datasource / database”的教程和解决问题的例子: directjump2java.blogspot.com 堆栈溢出 论坛spring 等等。 但是当我每次运行它时,配置只读取我的第一个数据库配置(MySql)并显示此错误Table ‘db_prod.ksei_lookup_holiday’ doesn’t exist db.prod是我的第一个数据库(MySql)而KSEI_LOOKUP_HOLIDAY是我的第二个数据库(Oracle),则 这是我的spring.xml org.hibernate.dialect.MySQL5Dialect true org.hibernate.dialect.Oracle10gDialect true 这是我的第一个数据库(MySql)的DAO实现 @Repository @Qualifier(value=”sessionFactory”) public class UserDaoImpl extends HibernateDaoSupport implements UserDao{ @Autowired private UserDaoImpl(SessionFactory sessionFactory){ setSessionFactory(sessionFactory); } 这是我的第二个数据库(Oracle)的DAO实现 @Repository @Qualifier(value=”sessionFactorySOAAPP”) public class UpdateKSEIDaoImpl extends HibernateDaoSupport implements UpdateKSEIDao{ @Autowired private UpdateKSEIDaoImpl(SessionFactory sessionFactorySOAAPP){ setSessionFactory(sessionFactorySOAAPP); } […]

谁负责MySQL和Hibernate之间主键的自动增量?

MySQL的 CREATE TABLE `role` ( `id_role` INT(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id_role`) ) AUTO_INCREMENT=1; 过冬 @Entity public class Role { private Integer idRole; @Column(name = “id_role”, precision = 10) @GeneratedValue @Id public Integer getIdRole() { return idRole; } public void setIdRole(Integer idRole) { this.idRole = idRole; } } 鉴于上述背景,谁在创建新role时负责id_role列的自动增量? 换句话说,Hibernate在运行create SQL语句之前是否设置了主键值,还是将其设置为null并让MySQL在获取所选主键时自动递增该字段?

Hibernate返回带有空值的列表(带有List类型的OneToMany注释)

我遇到一个问题,因为Hibernate(4.1.8.FINAL)返回一个包含NULL值的列表(单向OneToMany映射)。 我得到的是:我得到一个大小为21的List,其中EntryAddress在第10个索引上,第二个Entry Address在第20个索引上。 Entry [addresses=[null, null, null, null, null, null, null, null, null, null, EntryAddress [id=5, entryId=3, precedence=10, line=Line 3.1], null, null, null, null, null, null, null, null, null, EntryAddress [id=6, entryId=3, precedence=20, line=Line 3.2]]] 我所期待的 – 我希望List只有两个EntryAddress对象: Entry [addresses=[EntryAddress [id=5, entryId=3, precedence=10, line=Line 3.1], EntryAddress [id=6, entryId=3, precedence=20, line=Line 3.2]]] 这是最小的源代码: @Entity @Table(name = […]

使用Java与MySql的Unix套接字连接,以避免JDBC的TCP / IP开销?

是否可以使用Java与MySql建立Unix套接字连接以避免JDBC的TCP / IP开销? 有没有人知道一个库(或者一些库,或许)使这成为可能?