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

  • Home
  • SEARCH
  • 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 6895417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:54:22+00:00 2026-05-27T06:54:22+00:00

A typical JPA entity looks like: @Entity public class Person { @Id private int

  • 0

A typical JPA entity looks like:

@Entity
public class Person {
  @Id
  private int id;
  private String name;
  private int age;
  private Calendar anniversary;
  ...
}

Note that the data type is not annotated on any of the member attributes.

I just read a note around Hibernate being not so usable with Scala’s data types and wondered if we could write some adaptors. I know we can write UserTypes for Scala types and UserCollectionTypes for Scala’s collections so adaptors may be possible.

The question I have is can I configure these data types somehow so JPA will automatically associate them with corresponding Scala types (e.g. BigDecimal‘s user type with BigDecimal attributes), without having to annotate each attribute with @Type?

  • 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-27T06:54:22+00:00Added an answer on May 27, 2026 at 6:54 am

    What you’re missing is that the JPA (in most implementations) maps to a relational database so it will map to an SQL type. Thus if you’re looking at the entity above it will map to a serialized object if you specify it, but more commonly it will map to a structure.

    Let’s play with your entity and add an Account to it:

    @Entity 
    public class Account
    {
      @Id
      private int id;
      private String name;
      private String password; //no bad don't do this really
    }
    
    @Entity
    public class Person {
      @Id
      private int id;
      private String name;
      private int age;
      private Account account; //custom type
      private Calendar anniversary;
      ...
    }
    

    If I run a JPQL query "SELECT p FROM Person p" I’m going to get->

      Person@AAAAAAAA //some memory with a member child of Account@BBBBBBBB
    

    In the database that’s going to look like:

    SELECT
      p.*,
      a.*
    FROM
      Person p INNER JOIN Account a 
        ON p.account_id = a.id
    

    The “custom type” just ended up as a collection of primitives in another table. Generally speaking that’s what you want with the JPA. You’re trying to map to a RDBMS 99% of the time and you’re trying to not use javax.sql because you might end up cutting yourself in frustration at the checked exceptions.

    Basically: think of it as the database instead of your custom type. That’s what the JPA is doing. All the dialects you see in Hibernate or Eclipselink etc… are doing just that. Taking primatives and then saying “When you said Long I mean BigInteger When you said String I think VARCHAR(2048). However you can refine those defaults with annotations like @Column so

    ...
    @Column(name="xyz", length="80")
    private String name
    ...
    //maps to
    COLUMN xyz VARCHAR(80)
    

    I’d highly recommend you look at a dialect for a database you know and read the code. It isn’t too bad. Hibernate has fantastic documentation for beginners. If you don’t know SQL learn it asap if you’re working with the JPA. You’ll need it.

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

Sidebar

Related Questions

Imagine, an Event entity references a Status Entity: @Entity @Table(name = event) public class
Typical way of creating a CSV string (pseudocode): Create a CSV container object (like
The typical ConfigParser generated file looks like: [Section] bar=foo [Section 2] bar2= baz Now,
Typical scenario: a class that a lot of people have worked on. I'd like
Typical Event Log message looks like below. There you can find very interesting fields
What follows is a typical dispose pattern example: public bool IsDisposed { get; private
A typical usage of the memcache (in pseudocode) looks like this: Map data =
A typical code fragment obtained from the YouTube embed feature looks like this: <object
A typical SWT sample code looks like the following code: final Display display =
A typical approach to avoid two instances of the same script running simultaneously looks

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.