Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Hibernate + JUnit test entity class generate database table     - Python2.7.7 source code analysis (Programming)

- ORA-08102 errors (Database)

- Linux SU command security Suggestions (Linux)

- Making Linux root file system problems on-link library (Programming)

- Local port forwarding using iptables under linux (Server)

- Linux data redirection (Linux)

- Explore Android SQLite3 multithreading (Programming)

- 8 Docker knowledge you may not know (Server)

- Using Libreoffice under ubuntu (Linux)

- Linux iptables firewall and vsftpd to resolve the issue (Linux)

- Https (SSL / TLS) Detailed principles (Server)

- JDK comes with tools jinfo (Linux)

- Verify the character set on MyCAT (Database)

- Alien Magic: RPM and DEB Mutual Convert (Linux)

- REDO LOG records management (Database)

- DNF Command Tutorial (Linux)

- The text formatting tools awk Linux system (Linux)

- linux system optimization and security configuration (Linux)

- Oracle database with test data insertion speed (Database)

- Docker use Dockerfile created since the launch of the service support SSH container mirror (Server)

 
         
  Hibernate + JUnit test entity class generate database table
     
  Add Date : 2017-01-08      
         
         
         
  Today, when the entity classes use hibernate annotation manner indicated generation database representation encountered some problems, after gathering some information, and finally summed up as follows:

The code I put a whole posted a few files come

This is the hibernate.cfg.xml file

< ? Xml version = '1.0' encoding = 'UTF-8'?>
< ! DOCTYPE hibernate-configuration PUBLIC
          "- // Hibernate / Hibernate Configuration DTD 3.0 // EN"
          "Http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
< -! Generated by MyEclipse Hibernate Tools -.>
< Hibernate-configuration>

 < Session-factory>
  < Property name = "hibernate.connection.driver_class"> com.mysql.jdbc.Driver < / property>
  < Property name = "hibernate.connection.url"> jdbc: mysql: // localhost: 3306 / phn_dsjava < / property>
  < Property name = "hibernate.connection.username"> root < / property>
  < Property name = "hibernate.connection.password"> 123456 < / property>
  < Property name = "hibernate.dialect"> org.hibernate.dialect.MySQLDialect < / property>
  < Property name = "hibernate.show_sql"> true < / property>
  < Property name = "format_sql"> true < / property>
  < Property name = "hibernate.hbm2ddl.auto"> update < / property>

  < Mapping class = "com.phn.bean.Announces" />

 < / Session-factory>

< / Hibernate-configuration>

This is the entity class Announces.java

package com.phn.bean;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/ **
 *
 * /
@Entity
@Table (Name = "t_announce")
public class Announces {

 private Integer id;
 private String announcement;
 private String title;
 private Date thetime;

 @Id
 @GeneratedValue
 @Column (Nullable = false)
 public Integer getId () {
  return this.id;
 }

 public void setId (Integer id) {
  this.id = id;
 }

 @Column (Length = 20000)
 public String getAnnouncement () {
  return this.announcement;
 }

 public void setAnnouncement (String announcement) {
  this.announcement = announcement;
 }

 @Column (Length = 100)
 public String getTitle () {
  return title;
 }

 public void setTitle (String title) {
  this.title = title;
 }

 public Date getThetime () {
  return thetime;
 }

 public void setThetime (Date thetime) {
  this.thetime = thetime;
 }

}

This is a test class HibernateAnnotationTest.java

package com.phn.junitTest;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.junit.Test;

import junit.framework.TestCase;

public class HibernateAnnotationTest extends TestCase {
 @Test
 public void testSQL () {
  AnnotationConfiguration configuration = new AnnotationConfiguration ();
  configuration.configure ();
  SessionFactory sessionFactory = configuration.buildSessionFactory ();
 }
}

--------------------------- Below is a problem to explain ------------------ ---------

Hibernate configuration file hibernate.cfg.xml located in the src directory. When unit testing, executing the following code will generate an exception.

Configuration cfg = new Configuration ();
SessionFactory sf = cfg.configure () buildSessionFactory ().;

abnormal:
org.hibernate.MappingException: An AnnotationConfiguration instance is required to use < mapping class = "***" />

Hibernate configuration file, if with < mapping class = "com.phn.Users" />, then the mapping class, using the Annotation mode. At initialization Configuation, use AnnoationConfiguration, the following code:

AnnotationConfiguration configuration = new AnnotationConfiguration ();
configuration.configure ();
SessionFactory sessionFactory = configuration.buildSessionFactory ();

Note: As used herein, hibernate version 3.3
Version low point may appear in the picture below this error, because the low version of hibernate jar package org.hibernate.engine.query.sql.NativeSQLQueryReturn class is missing, and therefore it is updated on the line
     
         
         
         
  More:      
 
- ORA-08102 errors (Database)
- Create the best introductory tutorial REST API (Linux)
- How to make Linux a non-root user uses less than 1024 ports (Linux)
- Cancel Root Command History under Linux (Linux)
- Forgot Linux root password (Linux)
- Bash Getopts - let your script supports command line parameters (Linux)
- Install Python 3.3.4 under CentOS 6.4 (Linux)
- Oracle 11g RAC installation considerations Miscellany (Database)
- Linux, Google Test (GTest) test environment to build step (Linux)
- NAT (network address translation) Realization (Linux)
- PostgreSQL use pgpool achieve high availability (Database)
- Installing PHP Memcache extension under Linux (Server)
- Which file system is most suitable for your Linux system (Linux)
- Syncthing: Private Security Synchronization tool to synchronize files between computers / folder (Linux)
- How to use Aptik to backup and restore Apps/PPAs under ubuntu (Linux)
- Getting Started with Linux system to learn: How to compress JPEG images on the command line (Linux)
- Spring Data JPA call a stored procedure examples (Programming)
- OpenSUSE 13.1 OpenSUSE 12.3 and how to install Cinnamon 2.2 Desktop (Linux)
- KVM add virtual disks (Linux)
- Go constructed using an interpreted language (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.