Hibernate将东方语言而不是拉丁文符号写入SQL Server [英] Hibernate Writing oriental instead of latin symbols into SQL Server

查看:167
本文介绍了Hibernate将东方语言而不是拉丁文符号写入SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JBOSS Hibernate工具对MS SQL Server进行反向工程,以获得我的数据模型对象。然后我用Java编写了一个小测试程序来打开一个会话,使用配置,实例化一个Customer对象,并将其保存到数据库中。



示例运行时将一条记录写入数据库并关闭会话。 b
$ b

奇怪的是,我以前从来没有见过将'东方'字符保存到数据库列中。



数据库: b
$ b

Windows 2012 R2 Standard上的SQL Server(Express)10.50.1600

列customerCode和customerName为nvarchar,null b $ b Java App:Eclipse Neon,Maven,Hibernate 4.3,Java 1.8


注意:我是Hibernate的新手。



我还可以尝试或重构什么?



我试过
的东西做一个SQL Insert与IBM数据工作室(成功)



没有成功


    在连接URL中添加UTF-8
  1. 在hibernate xml中添加UTF-8
  2. 创建一个SqlServerDialectWithNvarchar类并将其输入到hibernate xml中。

public class SqlServerDialectWithNvarchar extends org.hibernate.dialect.SQLServerDialect {

  public SqlServerDialectWithNvarchar(){
registerHibernateType(Types.NVARCHAR,4000,string);
registerColumnType(Types.BIGINT,bigint);
registerColumnType(Types.BIT,bit);
registerColumnType(Types.CHAR,nchar(1));
registerColumnType(Types.VARCHAR,4000,nvarchar($ l));
registerColumnType(Types.VARCHAR,nvarchar(max));
registerColumnType(Types.VARBINARY,4000,varbinary($ 1));
registerColumnType(Types.VARBINARY,varbinary(max));
registerColumnType(Types.BLOB,varbinary(max));
registerColumnType(Types.CLOB,nvarchar(max));
}

}

主程序:

  public static void main(String [] args){
String btnName =OrderTrack.java ;

System.out.println(btnName +started。);
System.out.println(btnName +hibernate.enh-tas.cfg.xml);

配置cfg1 = new Configuration();
cfg1.configure(/ hibernate.enh-tas.cfg.xml);

SessionFactory sf1 = cfg1.configure()。buildSessionFactory();

System.out.println(btnName +open hibernate session。);
会话会话= sf1.openSession();
session.beginTransaction();

TblCustomers customer = new TblCustomers();
customer.setCustomerName(TEST XXX);
customer.setCustomerCode(DELETE ME);

session.persist(customer);
session.getTransaction()。commit();

System.out.println(btnName +关闭休眠会话。);
session.close();
System.out.println(btnName +session closed。);

$ b $ / code>

在主程序运行后使用IBM Data Studio进行SELECT查询 p>

  customerId customerCode customerName 
----------- ----------- --- ---------------
30Ԁ䐉䱅⁅䕍合t合卅⁔塘X

Hibernate XML

  hibernate-configuration> 
< session-factory>
< property name =hibernate.connection.useUnicode> true< / property>
< property name =hibernate.connection.characterEncoding> utf-8< / property>
< property name =hibernate.bytecode.use_reflection_optimizer> false< / property>
< property name =hibernate.connection.driver_class> com.microsoft.sqlserver.jdbc.SQLServerDriver< / property>
< property name =hibernate.connection.password> pwd< / property>
< property name =hibernate.connection.url> jdbc:sqlserver:// serverhost:1433; characterEncoding = UTF-8;< / property>
< property name =hibernate.connection.username> tms< / property>
< property name =hibernate.dialect> org.hibernate.dialect.SQLServerDialect< / property>
< property name =hibernate.encrypt> false< / property>
< property name =hibernate.search.autoregister_listeners> true< / property>
< property name =hibernate.show_sql> false< / property>
< property name =hibernate.validator.apply_to_ddl> false< / property>

客户类
/ **
*由hbm2java生成的TblCustomers
* /

  @Entity 
@Table(name =tblCustomers,schema =dbo,catalog = TAS,uniqueConstraints = @UniqueConstraint(columnNames = {
customerCode,customerContact}))
public class TblCustomers implements java.io.Serializable {

private Integer客户ID;
private TblFrequency tblFrequency;
私有布尔customerLocked;
私有布尔customerDeleted;
私有序列化customerCode;
专用可序列化的customerName;
私有布尔值customerIsOperator;
私人布尔customerIsSupplier;
私有布尔值customerIsOwner;
私有布尔值customerIsDrawer;
私有序列化customerContact;
私有序列化customerContactPosition;
私有序列化customerAddress1;
私有序列化customerAddress2;
私有可串行化customerTown;
私有可序列化customerCounty;
私有序列化customerPostCode;
私有序列化customerCountry;
私有序列化customerTelNo;
私有序列化customerFaxNo;
私有序列化customerEmail1;
私有序列化customerEmail2;
私有序列化customerEmail3;
私有序列化customerEmail4;
私有序列化customerEmail5;
私有序列化customerInvoiceName;
私有序列化customerInvoiceAddress1;
私有序列化customerInvoiceAddress2;
私有序列化customerInvoiceTown;
私有序列化customerInvoiceCounty;
私有序列化customerInvoicePostCode;
私有序列化customerInvoiceCountry;
私有序列化customerDefermentAccountNo;
private double customerBond;
private double customerBondTrigger;
private double customerBondRemaining;
私有序列化customerNotes;
private Integer customerCustomerGroupId;
私有序列化customerRdcocode;
private serializable customerVatregNo;
私有布尔值customerIsHoldingAccount;
私人套餐< TblContacts> tblContactses = new HashSet(0);
私人套餐< TblMovementCustomers> tblMovementCustomerses = new HashSet(0);
private Set< TblTas2orderConfig> tblTas2orderConfigsForTas2ocCarrierNumber = new HashSet(0);
私人套餐< TblJournalCustomers> tblJournalCustomerses = new HashSet(0);
private Set< TblTas2orderConfig> tblTas2orderConfigsForTas2ocCustomerNumber = new HashSet(0);
私人设定< TblSites> tblSiteses = new HashSet(0);
私人套餐< TblWomovements> tblWomovementses = new HashSet(0);
私人设定< TblTas2destinations> tblTas2destinationses = new HashSet(0);
private Set< TblTas2orderConfig> tblTas2orderConfigsForTas2ocSupplierNumber = new HashSet(0);
private Set< TblTas2orderProduct> tblTas2orderProducts = new HashSet(0);
私人套餐< TblCustomerStocks> tblCustomerStockses = new HashSet(0);

public TblCustomers(){
}

public TblCustomers(TblFrequency tblFrequency,Boolean customerLocked,Boolean customerDeleted,
可序列化的customerCode,可序列化的customerName,布尔customerIsOperator ,
布尔值customerIsSupplier,布尔值customerIsOwner,布尔值customerIsDrawer,可序列化customerContact,
可序列化customerContactPosition,可序列化customerAddress1,可序列化customerAddress2,
可序列化customerTown,可序列化customerCounty,可序列化customerPostCode,
可序列化customerCountry,可序列化customerTelNo,可序列化customerFaxNo,
可序列化customerEmail1,可序列化customerEmail2,可序列化customerEmail3,
可序列化customerEmail4,可序列化customerEmail5,可序列化customerInvoiceName,
可序列化customerInvoiceAddress1,可序列化customerI序列化customerInvoiceCounty,序列化customerInvoicePostCode,
序列化customerInvoiceCountry,序列化customerDefermentAccountNo,双重customerBond,
双重customerBondTrigger,双重customerBondRemaining,序列化customerNotes,
整数customerCustomerGroupId,序列化customerRdcocode ,序列化customerVatregNo,
布尔customerIsHoldingAccount,集tblContactses,集tblMovementCustomerses,
组tblTas2orderConfigsForTas2ocCarrierNumber,集tblJournalCustomerses,
组tblTas2orderConfigsForTas2ocCustomerNumber,集tblSiteses,集tblWomovementses,
组tblTas2destinationses,集tblTas2orderConfigsForTas2ocSupplierNumber,设置tblTas2orderProducts,
设置tblCustomerStockses){
this.tblFrequency = tblFrequency;
this.customerLocked = customerLocked;
this.customerDeleted = customerDeleted;
this.customerCode = customerCode;
this.customerName = customerName;
this.customerIsOperator = customerIsOperator;
this.customerIsSupplier = customerIsSupplier;
this.customerIsOwner = customerIsOwner;
this.customerIsDrawer = customerIsDrawer;
this.customerContact = customerContact;
this.customerContactPosition = customerContactPosition;
this.customerAddress1 = customerAddress1;
this.customerAddress2 = customerAddress2;
this.customerTown = customerTown;
this.customerCounty = customerCounty;
this.customerPostCode = customerPostCode;
this.customerCountry = customerCountry;
this.customerTelNo = customerTelNo;
this.customerFaxNo = customerFaxNo;
this.customerEmail1 = customerEmail1;
this.customerEmail2 = customerEmail2;
this.customerEmail3 = customerEmail3;
this.customerEmail4 = customerEmail4;
this.customerEmail5 = customerEmail5;
this.customerInvoiceName = customerInvoiceName;
this.customerInvoiceAddress1 = customerInvoiceAddress1;
this.customerInvoiceAddress2 = customerInvoiceAddress2;
this.customerInvoiceTown = customerInvoiceTown;
this.customerInvoiceCounty = customerInvoiceCounty;
this.customerInvoicePostCode = customerInvoicePostCode;
this.customerInvoiceCountry = customerInvoiceCountry;
this.customerDefermentAccountNo = customerDefermentAccountNo;
this.customerBond = customerBond;
this.customerBondTrigger = customerBondTrigger;
this.customerBondRemaining = customerBondRemaining;
this.customerNotes = customerNotes;
this.customerCustomerGroupId = customerCustomerGroupId;
this.customerRdcocode = customerRdcocode;
this.customerVatregNo = customerVatregNo;
this.customerIsHoldingAccount = customerIsHoldingAccount;
this.tblContactses = tblContactses;
this.tblMovementCustomerses = tblMovementCustomerses;
this.tblTas2orderConfigsForTas2ocCarrierNumber = tblTas2orderConfigsForTas2ocCarrierNumber;
this.tblJournalCustomerses = tblJournalCustomerses;
this.tblTas2orderConfigsForTas2ocCustomerNumber = tblTas2orderConfigsForTas2ocCustomerNumber;
this.tblSiteses = tblSiteses;
this.tblWomovementses = tblWomovementses;
this.tblTas2destinationses = tblTas2destinationses;
this.tblTas2orderConfigsForTas2ocSupplierNumber = tblTas2orderConfigsForTas2ocSupplierNumber;
this.tblTas2orderProducts = tblTas2orderProducts;
this.tblCustomerStockses = tblCustomerStockses;


@Id
@GeneratedValue(strategy = GenerationType.AUTO)

@Column(name =customerId,unique = true,nullable = false)
public Integer getCustomerId(){
return this.customerId;
}

public void setCustomerId(Integer customerId){
this.customerId = customerId;


@Column(name =customerCode)
public Serializable getCustomerCode(){
return this.customerCode;
}

public void setCustomerCode(Serializable customerCode){
this.customerCode = customerCode;


@Column(name =customerName)
public Serializable getCustomerName(){
return this.customerName;
}

public void setCustomerName(Serializable customerName){
this.customerName = customerName;

控制台输出(hibernate.show_sql = true)


$ $ $ $ $ $ $ $ $ $ $ $ $ DEBUG $ begin $ b $ DEBUG获取JDBC连接
DEBUG获得JDBC连接
DEBUG - 初始自动提交状态:false
DEBUG - 立即执行标识插入
DEBUG - 插入到TAS.dbo.tblCustomers(customerAddress1,customerAddress2,customerBond,customerBondRemaining,customerBondTrigger,customerCode,customerContact,customerContactPosition, customerCountry,customerCounty,customer_customerGroupId,customerDefermentAccountNo,customerDeleted,customerEmail1,customerEmail2,customerEmail3,customerEmail4,customerEmail5,customerFaxNo,customerInvoiceAddress1,customerInvoiceAddress2,customerInvoiceCountry,customerInvoiceCounty,customerInvoiceName,customerInvoicePostCode,customerInvoiceTown,customerIsDrawer,customerIsHoldingAccount,customerIsOperator,customerIsOwner,customerIsSupplier,客户名称,customerNotes,customerPostCode,customerRDCOCode,customerTelNo,customerTown,customerVATRegNo,customerFrequencyId)值(?,?,?,?,?,?,?,? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
Hibernate:插入到TAS.dbo.tblCustomers(customerAddress1,customerAddress2,customerBond,customerBondRemaining,customerBondTrigger,customerCode,customerContact,customerContactPosition,customerCountry,customerCounty,customer_customerGroupId,customerDefermentAccountNo,customerDeleted,customerEmail1,customerEmail2,customerEmail3,customerEmail4,customerEmail5, customerFoiceNo,customerInvoiceAddress1,customerInvoiceAddress2,customerInvoiceCountry,customerInvoiceCounty,customerInvoiceName,customerInvoicePostCode,customerInvoiceTown,customerIsDrawer,customerIsHoldingAccount,customerIsOperator,customerIsOwner,customerIsSupplier,customerLocked,customerName,customerNotes,customerP ostCode,customerRDCOCode,customerTelNo,customerTown,customerVATRegNo,customerFrequencyId)的值(,,,,,,,,,,,,,,,,,,,,,,,,,, $,$,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
DEBUG - 本地生成的标识:37
调试 - 提交
调试 - 处理刷新时间级联
调试 - 脏检查集合
调试 - 收集找到:[com.xpagesbeast.data.entities。 enh.TblCustomers.tblContactses#37],是:[< unreferenced>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblCustomerStockses#37] <未引用>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblJournalCustomerses#37],是:[< unreferenced>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblMovementCustomerses#37],是:[<未引用>](已初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblSiteses#37],是:[< unreferenced>](初始化)
DEBUG - 找到集合:[com.xpagesbeast.data。 entities.enh.TblCustomers.tblTas2destinationses#37]:[< unreferenced>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocCarrierNumber#37],was :[< unreferenced>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocCustomerNumber#37],是:[< unreferenced>](初始化)
DEBUG - 找到的集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocSupplierNumber#37],是:[< unreferenced>](初始化)
DEBUG - 找到集合:[com.xpagesbeast。 data.entities.enh.TblCustomers.tblTas2orderProducts#37]是:[<未引用>](已初始化)
DEBUG - 找到收集:[com.xpagesb (未初始化)
DEBUG - 刷新:0个插入,0个更新,0个删除至1个对象
DEBUG - 刷新:11个(重新创建),0个更新,0个清除到11个集合
DEBUG - 上市实体:
DEBUG - com.xpagesbeast.data.entities.enh.TblCustomers {customerInvoicePostCode = null,customerContactPosition = null,customerDefermentAccountNo = null,tblCustomerStockses = [],tblTas2destinationses = [],customerIsDrawer = null,customerInvoiceCountry = null,tblContactses = [],customerCustomerGroupId = null,tblWomovementses = [],
$ b $ customerName = TEST XXX customerDeleted = null,customerBondTrigger = null,customerTown = null,customerVatregNo = null,tblMovementCustomerses = [],tblSiteses = [],tblTas2orderConfigsForTas2ocCarrierNumber = [],customerInvoiceName = null,
$ b customerCode = DELETE ME,customerEmail1 = null,customerNotes = null,customerEmail3 = null,customerEmail2 = null,customerCountry = null ,customerEmail5 = null,customerInvoiceAddress1 = null,tblTas2orderConfigsForTas2ocCustomerNumber = [],customerEmail4 = null,customerInvoiceAddress2 = null,customerIsOwner = null,tblTas2orderProducts = [],customerBondRemaining = null,customerFaxNo = null,customerIsSupplier = null,customerContact = null,customerPostCode = null ,customerId = 37,customerCounty = null,customerRdcocode = null,customerLocked = null,customerBond = null,tblTas2orderConfigsForTas2ocSupplierNumber = [],customerTelNo = null,customerInvoiceCounty = null,customerIsHoldingAccount = null,tblJournalCustomerses = [],tblFrequency = null,customerIsOperator = null ,customerAddress1 = null,customerAddress2 = null,customerInvoiceTown = null}
DEBUG - 插入集合:[com.xpagesbeast.data.entities.enh.TblCustomers.tblContactses#37]
DEBUG - 集合为空
DEBUG - 提交的JDBC连接
main.java关闭hibernate会话。
DEBUG - 释放JDBC连接
DEBUG - 释放JDBC连接
main.java会话关闭。
DEBUG - 连接池现在已被认为已启动;最小尺寸将保留


解决方案

更改您的字段实体类TblCustomers,其类型可串行化为String。



例如:更改

private可序列化的customerCode;



  private String customerCode; 

更改相应的setter和getter方法。



然后尝试运行您的应用程序。


I used JBOSS Hibernate tools to reverse engineer the MS SQL Server to get my data model objects.

I then wrote a small test program in Java to open a session, use the configuration, instantiate a Customer object, persist it into the database.

The sample runs writing one record to the database and closing the session.

What is weird, I have never seen this before is the 'oriental' characters being saved into the database columns.

Database:

SQL Server (Express) 10.50.1600 on Windows 2012 R2 Standard
Columns customerCode and customerName are nvarchar, null
Java App: Eclipse Neon, Maven, Hibernate 4.3, Java 1.8

NOTE: I am a newbie to Hibernate.

What else can I try or refactor?

Things I tried Do a SQL Insert with IBM data studio (success)

No Success

  1. Add the UTF-8 in connection url
  2. Add the UTF-8 in hibernate xml
  3. Create a SqlServerDialectWithNvarchar Class and enter it into hibernate xml.

public class SqlServerDialectWithNvarchar extends org.hibernate.dialect.SQLServerDialect{

public SqlServerDialectWithNvarchar(){
    registerHibernateType(Types.NVARCHAR, 4000, "string");
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.BIT, "bit");
    registerColumnType(Types.CHAR, "nchar(1)");
    registerColumnType(Types.VARCHAR, 4000, "nvarchar($l)");
    registerColumnType(Types.VARCHAR, "nvarchar(max)");
    registerColumnType(Types.VARBINARY, 4000, "varbinary($1)");
    registerColumnType(Types.VARBINARY, "varbinary(max)");
    registerColumnType(Types.BLOB, "varbinary(max)");
    registerColumnType(Types.CLOB, "nvarchar(max)");
}

}

Main Program:

public static void main(String[] args) {
    String btnName = "OrderTrack.java ";

    System.out.println(btnName + " started.");
    System.out.println(btnName + " hibernate.enh-tas.cfg.xml");

    Configuration cfg1 = new Configuration();
    cfg1.configure("/hibernate.enh-tas.cfg.xml");

    SessionFactory sf1 = cfg1.configure().buildSessionFactory();

    System.out.println(btnName + " open hibernate session.");
    Session session = sf1.openSession();
    session.beginTransaction();

    TblCustomers customer = new TblCustomers();
    customer.setCustomerName("TEST XXX");
    customer.setCustomerCode("DELETE ME");

    session.persist(customer);
    session.getTransaction().commit();

    System.out.println(btnName + " closing hibernate session.");
    session.close();
    System.out.println(btnName + " session closed.");

}

SELECT Query using IBM Data Studio after main program runs

 customerId     customerCode    customerName
 ----------     --------------  ---------------
         30     Ԁt䐉䱅呅⁅䕍        Ԁt合卅⁔塘X      

Hibernate XML

hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.useUnicode">true</property>
        <property name="hibernate.connection.characterEncoding">utf-8</property>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="hibernate.connection.password">pwd</property>
        <property name="hibernate.connection.url">jdbc:sqlserver://serverhost:1433;characterEncoding=UTF-8;</property>
        <property name="hibernate.connection.username">tms</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
        <property name="hibernate.encrypt">false</property>
        <property name="hibernate.search.autoregister_listeners">true</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.validator.apply_to_ddl">false</property>

Customer Class /** * TblCustomers generated by hbm2java */

@Entity
@Table(name = "tblCustomers", schema = "dbo", catalog = "TAS", uniqueConstraints = @UniqueConstraint(columnNames = {
        "customerCode", "customerContact" }))
public class TblCustomers implements java.io.Serializable {

    private Integer customerId;
    private TblFrequency tblFrequency;
    private Boolean customerLocked;
    private Boolean customerDeleted;
    private Serializable customerCode;
    private Serializable customerName;
    private Boolean customerIsOperator;
    private Boolean customerIsSupplier;
    private Boolean customerIsOwner;
    private Boolean customerIsDrawer;
    private Serializable customerContact;
    private Serializable customerContactPosition;
    private Serializable customerAddress1;
    private Serializable customerAddress2;
    private Serializable customerTown;
    private Serializable customerCounty;
    private Serializable customerPostCode;
    private Serializable customerCountry;
    private Serializable customerTelNo;
    private Serializable customerFaxNo;
    private Serializable customerEmail1;
    private Serializable customerEmail2;
    private Serializable customerEmail3;
    private Serializable customerEmail4;
    private Serializable customerEmail5;
    private Serializable customerInvoiceName;
    private Serializable customerInvoiceAddress1;
    private Serializable customerInvoiceAddress2;
    private Serializable customerInvoiceTown;
    private Serializable customerInvoiceCounty;
    private Serializable customerInvoicePostCode;
    private Serializable customerInvoiceCountry;
    private Serializable customerDefermentAccountNo;
    private Double customerBond;
    private Double customerBondTrigger;
    private Double customerBondRemaining;
    private Serializable customerNotes;
    private Integer customerCustomerGroupId;
    private Serializable customerRdcocode;
    private Serializable customerVatregNo;
    private Boolean customerIsHoldingAccount;
    private Set<TblContacts> tblContactses = new HashSet(0);
    private Set<TblMovementCustomers> tblMovementCustomerses = new HashSet(0);
    private Set<TblTas2orderConfig> tblTas2orderConfigsForTas2ocCarrierNumber = new HashSet(0);
    private Set<TblJournalCustomers> tblJournalCustomerses = new HashSet(0);
    private Set<TblTas2orderConfig> tblTas2orderConfigsForTas2ocCustomerNumber = new HashSet(0);
    private Set<TblSites> tblSiteses = new HashSet(0);
    private Set<TblWomovements> tblWomovementses = new HashSet(0);
    private Set<TblTas2destinations> tblTas2destinationses = new HashSet(0);
    private Set<TblTas2orderConfig> tblTas2orderConfigsForTas2ocSupplierNumber = new HashSet(0);
    private Set<TblTas2orderProduct> tblTas2orderProducts = new HashSet(0);
    private Set<TblCustomerStocks> tblCustomerStockses = new HashSet(0);

    public TblCustomers() {
    }

    public TblCustomers(TblFrequency tblFrequency, Boolean customerLocked, Boolean customerDeleted,
            Serializable customerCode, Serializable customerName, Boolean customerIsOperator,
            Boolean customerIsSupplier, Boolean customerIsOwner, Boolean customerIsDrawer, Serializable customerContact,
            Serializable customerContactPosition, Serializable customerAddress1, Serializable customerAddress2,
            Serializable customerTown, Serializable customerCounty, Serializable customerPostCode,
            Serializable customerCountry, Serializable customerTelNo, Serializable customerFaxNo,
            Serializable customerEmail1, Serializable customerEmail2, Serializable customerEmail3,
            Serializable customerEmail4, Serializable customerEmail5, Serializable customerInvoiceName,
            Serializable customerInvoiceAddress1, Serializable customerInvoiceAddress2,
            Serializable customerInvoiceTown, Serializable customerInvoiceCounty, Serializable customerInvoicePostCode,
            Serializable customerInvoiceCountry, Serializable customerDefermentAccountNo, Double customerBond,
            Double customerBondTrigger, Double customerBondRemaining, Serializable customerNotes,
            Integer customerCustomerGroupId, Serializable customerRdcocode, Serializable customerVatregNo,
            Boolean customerIsHoldingAccount, Set tblContactses, Set tblMovementCustomerses,
            Set tblTas2orderConfigsForTas2ocCarrierNumber, Set tblJournalCustomerses,
            Set tblTas2orderConfigsForTas2ocCustomerNumber, Set tblSiteses, Set tblWomovementses,
            Set tblTas2destinationses, Set tblTas2orderConfigsForTas2ocSupplierNumber, Set tblTas2orderProducts,
            Set tblCustomerStockses) {
        this.tblFrequency = tblFrequency;
        this.customerLocked = customerLocked;
        this.customerDeleted = customerDeleted;
        this.customerCode = customerCode;
        this.customerName = customerName;
        this.customerIsOperator = customerIsOperator;
        this.customerIsSupplier = customerIsSupplier;
        this.customerIsOwner = customerIsOwner;
        this.customerIsDrawer = customerIsDrawer;
        this.customerContact = customerContact;
        this.customerContactPosition = customerContactPosition;
        this.customerAddress1 = customerAddress1;
        this.customerAddress2 = customerAddress2;
        this.customerTown = customerTown;
        this.customerCounty = customerCounty;
        this.customerPostCode = customerPostCode;
        this.customerCountry = customerCountry;
        this.customerTelNo = customerTelNo;
        this.customerFaxNo = customerFaxNo;
        this.customerEmail1 = customerEmail1;
        this.customerEmail2 = customerEmail2;
        this.customerEmail3 = customerEmail3;
        this.customerEmail4 = customerEmail4;
        this.customerEmail5 = customerEmail5;
        this.customerInvoiceName = customerInvoiceName;
        this.customerInvoiceAddress1 = customerInvoiceAddress1;
        this.customerInvoiceAddress2 = customerInvoiceAddress2;
        this.customerInvoiceTown = customerInvoiceTown;
        this.customerInvoiceCounty = customerInvoiceCounty;
        this.customerInvoicePostCode = customerInvoicePostCode;
        this.customerInvoiceCountry = customerInvoiceCountry;
        this.customerDefermentAccountNo = customerDefermentAccountNo;
        this.customerBond = customerBond;
        this.customerBondTrigger = customerBondTrigger;
        this.customerBondRemaining = customerBondRemaining;
        this.customerNotes = customerNotes;
        this.customerCustomerGroupId = customerCustomerGroupId;
        this.customerRdcocode = customerRdcocode;
        this.customerVatregNo = customerVatregNo;
        this.customerIsHoldingAccount = customerIsHoldingAccount;
        this.tblContactses = tblContactses;
        this.tblMovementCustomerses = tblMovementCustomerses;
        this.tblTas2orderConfigsForTas2ocCarrierNumber = tblTas2orderConfigsForTas2ocCarrierNumber;
        this.tblJournalCustomerses = tblJournalCustomerses;
        this.tblTas2orderConfigsForTas2ocCustomerNumber = tblTas2orderConfigsForTas2ocCustomerNumber;
        this.tblSiteses = tblSiteses;
        this.tblWomovementses = tblWomovementses;
        this.tblTas2destinationses = tblTas2destinationses;
        this.tblTas2orderConfigsForTas2ocSupplierNumber = tblTas2orderConfigsForTas2ocSupplierNumber;
        this.tblTas2orderProducts = tblTas2orderProducts;
        this.tblCustomerStockses = tblCustomerStockses;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

    @Column(name = "customerId", unique = true, nullable = false)
    public Integer getCustomerId() {
        return this.customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    @Column(name = "customerCode")
    public Serializable getCustomerCode() {
        return this.customerCode;
    }

    public void setCustomerCode(Serializable customerCode) {
        this.customerCode = customerCode;
    }

    @Column(name = "customerName")
    public Serializable getCustomerName() {
        return this.customerName;
    }

    public void setCustomerName(Serializable customerName) {
        this.customerName = customerName;
    }

Console Output (hibernate.show_sql = true)

    DEBUG - begin
    DEBUG - Obtaining JDBC connection
    DEBUG - Obtained JDBC connection
    DEBUG - initial autocommit status: false
    DEBUG - Executing identity-insert immediately
    DEBUG - insert into TAS.dbo.tblCustomers (customerAddress1, customerAddress2, customerBond, customerBondRemaining, customerBondTrigger, customerCode, customerContact, customerContactPosition, customerCountry, customerCounty, customer_customerGroupId, customerDefermentAccountNo, customerDeleted, customerEmail1, customerEmail2, customerEmail3, customerEmail4, customerEmail5, customerFaxNo, customerInvoiceAddress1, customerInvoiceAddress2, customerInvoiceCountry, customerInvoiceCounty, customerInvoiceName, customerInvoicePostCode, customerInvoiceTown, customerIsDrawer, customerIsHoldingAccount, customerIsOperator, customerIsOwner, customerIsSupplier, customerLocked, customerName, customerNotes, customerPostCode, customerRDCOCode, customerTelNo, customerTown, customerVATRegNo, customerFrequencyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    Hibernate: insert into TAS.dbo.tblCustomers (customerAddress1, customerAddress2, customerBond, customerBondRemaining, customerBondTrigger, customerCode, customerContact, customerContactPosition, customerCountry, customerCounty, customer_customerGroupId, customerDefermentAccountNo, customerDeleted, customerEmail1, customerEmail2, customerEmail3, customerEmail4, customerEmail5, customerFaxNo, customerInvoiceAddress1, customerInvoiceAddress2, customerInvoiceCountry, customerInvoiceCounty, customerInvoiceName, customerInvoicePostCode, customerInvoiceTown, customerIsDrawer, customerIsHoldingAccount, customerIsOperator, customerIsOwner, customerIsSupplier, customerLocked, customerName, customerNotes, customerPostCode, customerRDCOCode, customerTelNo, customerTown, customerVATRegNo, customerFrequencyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    DEBUG - Natively generated identity: 37
    DEBUG - committing
    DEBUG - Processing flush-time cascades
    DEBUG - Dirty checking collections
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblContactses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblCustomerStockses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblJournalCustomerses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblMovementCustomerses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblSiteses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2destinationses#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocCarrierNumber#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocCustomerNumber#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderConfigsForTas2ocSupplierNumber#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblTas2orderProducts#37], was: [<unreferenced>] (initialized)
    DEBUG - Collection found: [com.xpagesbeast.data.entities.enh.TblCustomers.tblWomovementses#37], was: [<unreferenced>] (initialized)
    DEBUG - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
    DEBUG - Flushed: 11 (re)creations, 0 updates, 0 removals to 11 collections
    DEBUG - Listing entities:
    DEBUG - com.xpagesbeast.data.entities.enh.TblCustomers{customerInvoicePostCode=null, customerContactPosition=null, customerDefermentAccountNo=null, tblCustomerStockses=[], tblTas2destinationses=[], customerIsDrawer=null, customerInvoiceCountry=null, tblContactses=[], customerCustomerGroupId=null, tblWomovementses=[], 

customerName=TEST XXX, customerDeleted=null,customerBondTrigger=null, customerTown=null, customerVatregNo=null, tblMovementCustomerses=[], tblSiteses=[], tblTas2orderConfigsForTas2ocCarrierNumber=[], customerInvoiceName=null, 

customerCode=DELETE ME, customerEmail1=null, customerNotes=null, customerEmail3=null, customerEmail2=null, customerCountry=null, customerEmail5=null, customerInvoiceAddress1=null, tblTas2orderConfigsForTas2ocCustomerNumber=[], customerEmail4=null, customerInvoiceAddress2=null, customerIsOwner=null, tblTas2orderProducts=[], customerBondRemaining=null, customerFaxNo=null, customerIsSupplier=null, customerContact=null, customerPostCode=null, customerId=37, customerCounty=null, customerRdcocode=null, customerLocked=null, customerBond=null, tblTas2orderConfigsForTas2ocSupplierNumber=[], customerTelNo=null, customerInvoiceCounty=null, customerIsHoldingAccount=null, tblJournalCustomerses=[], tblFrequency=null, customerIsOperator=null, customerAddress1=null, customerAddress2=null, customerInvoiceTown=null}
    DEBUG - Inserting collection: [com.xpagesbeast.data.entities.enh.TblCustomers.tblContactses#37]
    DEBUG - Collection was empty
    DEBUG - committed JDBC Connection
    main.java  closing hibernate session.
    DEBUG - Releasing JDBC connection
    DEBUG - Released JDBC connection
    main.java  session closed.
    DEBUG - Connection pool now considered primed; min-size will be maintained

解决方案

Change the fields in your entity class TblCustomers, whose type are serializable to String.

For eg: change
private Serializable customerCode;

to

private String customerCode;

Change the corresponding setter and getter methods as well.

Then try running your application.

这篇关于Hibernate将东方语言而不是拉丁文符号写入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆