Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2016
    Posts
    2

    Question Unanswered: postgres UUID with java

    Hi,

    I have an application which have uniqueidentifier field in sql and String as field in Java. Now I want to use same configuration with postgres. I want to have uuid field in database and String field in Java. But when I am trying this configuration with hibernate, I am getting type cast error. So anyone can help me if it is possible to use this config for postgres using hibernate 5 with hbm.

    Thanks in advance.

    Regards,
    Ankit

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by ankit.b.bajpai View Post
    I have an application which have uniqueidentifier field in sql and String as field in Java. Now I want to use same configuration with postgres.
    Sorry, I don't understand that.

    Postgres is using "SQL". So if you already use UUIDs through SQL where exactly is your problem?
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  3. #3
    Join Date
    Sep 2016
    Posts
    2
    This is my scenario :
    In MS-SQL server db I have following table :
    CREATE TABLE [dbo].[user1](
    [Id] [uniqueidentifier] NOT NULL,
    [log_in_time] [datetime] NULL,
    [log_out_time] [datetime] NULL,
    [login_fail_time] [datetime] NULL,
    [session_id] [varchar](255) NULL,
    [userid] [varchar](255) NULL,
    PRIMARY KEY CLUSTERED

    In java we have following POJO for id field as :

    String Id;

    public void setId(String id){
    this.Id = id;
    }

    public String getId(){
    return this.Id;
    }

    In postgres we have following table structure:

    CREATE TABLE public.user1
    (
    id uuid NOT NULL,
    log_in_time timestamp without time zone,
    log_out_time timestamp without time zone,
    login_fail_time timestamp without time zone,
    session_id character varying(255),
    userid character varying(255),
    CONSTRAINT user1_pkey PRIMARY KEY (id)
    )

    NOw when I try to use same java file with postgres, we get type cast error. This is my issue, I want to use String as java class variable and uuid in database.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by ankit.b.bajpai View Post
    Now when I try to use same java file with postgres, we get type cast error. This is my issue, I want to use String as java class variable and uuid in database.
    This is actually a Java question, not a Postgres question.

    But you need to at least show us the Java (JDBC) code that fails. E.g. the SELECT statement and the Java code that processes the ResultSet or the Java code that populates the PreparedStatement and calls executeUpdate()
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

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
  •