Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Hibernate + JUnit test entity class generate database table     - Linux iostat command example explanation (Linux)

- Java source implementation of the observer pattern instance (Programming)

- MySQL5.7 JSON type using presentation (Database)

- Linux crontab use (Linux)

- Linux firewall settings -DNS server articles (Server)

- The Java way to stop a thread of execution (Programming)

- Ubuntu Telnet service settings (Linux)

- How to install PlayOnLinux 4.2.5 under Ubuntu 14.04 / 12.04 (Linux)

- Linux Getting Started tutorial: Experience Xen Virtual Machine chapter (Linux)

- Additional SQL Server 5123 database reported error (Database)

- First start with Kali Linux 2.0 (Linux)

- Java programmers talk about those advanced knowledge and direction (Programming)

- Linux (Ubuntu) How iptables port mapping (Server)

- C ++ overloaded stream insertion operator and the stream extraction operator (Programming)

- Processor in protected mode of protection (Linux)

- SUSE Linux install Oracle 10g and problem solving (Linux)

- Gentoo: startx appeared Failed to load module Problem Solving (Linux)

- Spring next ActiveMQ combat (Programming)

- Linux system performance monitoring with Nmon (Linux)

- Oracle 12c users create (Database)

 
         
  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:      
 
- Ubuntu configuration SVN and http mode access (Server)
- Oracle 12CIN-memory in table spaces (Database)
- Log4cplus logging facility configuration, installation, testing (Linux)
- Configuring automatic mail GAMIT under CentOS system (Linux)
- Oracle how to assess the true concurrent session (Database)
- MongoDB upgrade to 2.6 (Database)
- C ++ casts New Standard Comments (Programming)
- Linux set to select the appropriate level of security of the network according to deployment (Linux)
- Android media library of analysis: MediaProvider (Programming)
- Android Fragment everything you need to know (Programming)
- Ubuntu install Oracle 10g process and problem solution (Linux)
- Windows Server 2012 R2 Datacenter install SQL Server 2016 CTP (Database)
- Systemd on RHEL7 (Linux)
- How to clear the v $ archived_log view expiration information (Database)
- linux network security experience (Linux)
- Linux compiler installation Redis (Database)
- Struts2 : combobox label use (Programming)
- To install the mail client terminal Evolution 3.13.2 under Ubuntu 14.04 (Linux)
- HA-Federation-HDFS + Yarn cluster deployment (Server)
- Linux source code analysis tool (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.