Results 1 to 3 of 3

Thread: MySQL - Java data types mapping

  1. #1
    Join Date
    Nov 2007
    Posts
    28

    Default MySQL - Java data types mapping

    Hi

    I'm confused when creating a Hibernate's persistent class.

    MySQL's unsigned int value ranges from 0 to 4,294,967,295.

    Java's int value ranges from -2,147,483,648 to of 2,147,483,647.

    Java's long value ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.


    Which Java primitive data type (int or long) we should map to the MySQL unsigned int?

  2. #2
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by hezjing View Post
    Hi

    I'm confused when creating a Hibernate's persistent class.

    MySQL's unsigned int value ranges from 0 to 4,294,967,295.

    Java's int value ranges from -2,147,483,648 to of 2,147,483,647.

    Java's long value ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.


    Which Java primitive data type (int or long) we should map to the MySQL unsigned int?
    The easiest way to answer this is to map a class with an int and a long on, and then let Hibernate autocreate the table for you, and see what MySQL types they map to.

    My guess is int->int and long->bigint though now I wonder how you store negative numbers !

  3. #3
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    The MySQL reference manual suggests using a Long - see http://dev.mysql.com/doc/refman/5.0/...nversions.html
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •