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 3999638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:40:59+00:00 2026-05-20T07:40:59+00:00

This is a JavaEE6 application using Hibernate and PostgreSQL. Users are created in the

  • 0

This is a JavaEE6 application using Hibernate and PostgreSQL. Users are created in the database with @GeneratedValue(strategy = GenerationType.AUTO) that generates Long ids. I am trying to use the user_id column of the database as the name column for the login realm ( e.g request.login(id.toString(), password ) ) because I can not ensure uniqueness of the names in the user_name column. However, using the built-in FORM authentication with Glassfishv3, it fails as it seems that the mechanism expect the column in the database to be a var char.
I am therefore looking for a way to populate at the same time that the user is created in the database a column string_id which value would be the id automatically generated translated into a String. I could do it in a subsequent operation but I was wondering if this could be done in one shot. I have tried @PrePersist but it seems that the id has not been generated at this stage. Or maybe there are smarter ways to perform the login ?

Thanks.

  • 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-20T07:41:00+00:00Added an answer on May 20, 2026 at 7:41 am

    You can do it in one shot –

    @Entity
    public class A {
      @Id @GeneratedValue(strategy=SEQUENCE)
      public Integer getId() { return id; }
      public void setId(Integer id) { this.id = id; }
      private Integer id;
    
      public String getName() { return name; }
      private void setName(String name) { this.name = name; }
      private String name;
    }
    
    Serializable id = em.unwrap(Session.class).save(a);
    a.setName("Why oh why redundancy? " + id);
    em.flush();
    

    Code copied from https://gist.github.com/786238

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

Sidebar

Related Questions

I'm using Apache Geronimo as my application server. And authentication is happening over LDAP
I am creating a signup application with validation and Captcha (using SimpleCaptcha). I am
I have a Java EE 6 Wicket application deployed with maven using IntelliJ IDEA
I'm trying to build an Java EE 6-application on GlassFish V3, using JSF 2.0,
This is my first attempt at using JSCookMenu and its homepage ( http://jscook.yuanheng.org/JSCookMenu/ )
This is driving me crazy. I created a Dynamic Web Project in eclipse and
This is my first time using the synchronized keyword, so I am still unsure
This is beyond both making sense and my control. That being said here is
I want to use a temp directory that will be unique to this build.
I'm developing a web application using Java EE6 and JSF 2.0. I have a

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.