2

I am new in java Hibernate and i try to make simple Hello world project.

I make a UserClass:

@Entity
@Table(name = "Table_User")
public class Table_User extends BaseObject implements Serializable {

    private String name;

    public Table_User(){
       //default  constructor
    }


    public TableUser(String name){
      this.name=name;
    }

    public String getName(){ return this.name; }
    public void setName(String name){ this.name=name; }


}

I am generate table using <property name="hibernate.hbm2ddl.auto" value="update"/>.

My question is.

How can i SET encoding for table and row name?

I want set utf8_czech_ci but is latin1_swedish_ci.

Thank you for your reply!

EDIT, my persisence.xml file is:

    <persistence-unit name="org.my"  transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>

            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

            <property name="hibernate.connection.password" value=""/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/myDb"/>

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.validator.apply_to_ddl" value="true" />

            <property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
            <property name="hibernate.c3p0.min_size" value="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="300"/>

        </properties>
    </persistence-unit>
</persistence>
3
  • Could you put here your persistence.xml file? Commented Dec 19, 2015 at 10:48
  • @MateuszKorwel sure, i editet. look. Commented Dec 19, 2015 at 10:50
  • Specify the "characterEncoding" to be "utf8" (or perhaps "UTF-8", check the Hibernate manual). Commented Dec 19, 2015 at 23:08

1 Answer 1

1

The encoding is always set at database level, not in the Hibernate mapping. If you are using MySQL, you can set it as follows:

CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_czech_ci;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.