Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 300847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:57:06+00:00 2026-05-12T06:57:06+00:00

I have 2 question I wanna make Mysql table that have charset utf8 but

  • 0

I have 2 question
I wanna make Mysql table that have charset utf8 but I don’t know where I shoud set the setting.
(I just have a hibernate.cfg.XMl no any .xml file for hibernate)
i dun want set mysql.ini file that default setting was UTF-8 I wanna put this setting in my hibernate.

second Question:
I have this table:

CREATE TABLE `buildingtel` (
`username` varchar(50) NOT NULL,
`buildingname` varchar(50) NOT NULL,
`tel` varchar(15) NOT NULL,
PRIMARY KEY (`username`,`buildingname`,`tel`),
KEY `FK_buildingtel_2` (`buildingname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

How can i Map these to and Java entity
I can do like this:

@Entity
@Table(name = "btel")
public class Btel {

@Id
@GeneratedValue
@Column(name = "id")
private int id;;
@Column(name = "username", length=50)
private String username;
@Column(name = "buildingname", length=50)
private int buildingname;
@Column(name = "tel", length=15)
private int tel;
//some setter & getter
}

but i want to set (username,buildingname,tel) together as a primary key how I can do it by annotation in hibernate

TanX in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:57:06+00:00Added an answer on May 12, 2026 at 6:57 am

    For UTF-8:

    <property name=”hibernate.connection.useUnicode”
    value=”true” />
    <property name=”hibernate.connection.characterEncoding”
    value=”UTF-8″ />
    

    As for setting a combined primary key, it is possible, but having worked with it I can say I wouldnt recommend it. From the documentation:

    You can define a composite primary key
    through several syntaxes:

    • annotate the component property as @Id and make the component class
      @Embeddable
    • annotate the component property as @EmbeddedId
    • annotate the class as @IdClass and annotate each property of the entity
      involved in the primary key with @Id

    This becomes a pain to work with, and it isn’t the recommended way to do this in Hibernate.

    What I would recommend instead is to use the @NaturalId annotation:

    While not used as identifier property,
    some (group of) properties represent
    natural identifier of an entity. This
    is especially true when the schema
    uses the recommended approach of using
    surrogate primary key even if a
    natural business key exists. Hibernate
    allows to map such natural properties
    and reuse them in a Criteria query.
    The natural identifier is composed of
    all the properties marked @NaturalId.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Question and QuestionTypes. In Question table there is a foreign key that
I have a question but dont have a answer, i wanna create a application
i have table question (mysql with php) which contains question,category(multiple) and subcat(multiple) its belong.
I know this question must have been covered endless of times, but I've searched
I have a question with php. I wanna generate a signature based on some
Well, I have a problem (ok, no real problem, but I wanna try out
My python env is 2.7 I know this is an old question, but I've
I know I asked these question before but I did not get the right
I have a question about NSUserDefault. Currently, i wanna write a function which save
Hey guys I have a question. I wanna create a profile page for each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.