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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:38:56+00:00 2026-05-12T05:38:56+00:00

In legacy database tables we have numbered columns like C1, C2, C3, C100 or

  • 0

In legacy database tables we have numbered columns like C1, C2, C3, C100 or M1, M2, M3, M100.
This columns represent BLOB data.

It is not possible to change anything it this database.

By using JPA Embeddable we map all of the columns to single fields. And then during embedding we override names by using 100 override annotations.

Recently we have switched to Hibernate and I’ve found things like UserCollectionType and CompositeUserType. But I hadn’t found any use cases that are close to mine.

Is it possible to implement some user type by using Hibernate to be able to map a bundle of columns to a collection without additional querying?

Edit:
As you probably noticed the names of columns can differ from table to table. I want to create one type like “LegacyArray” with no need to specify all of the @Columns each time I use this type.
But instead I’d use

  @Type(type = "LegacyArrayUserType",
        parameters =
   {
      @Parameter(name = "prefix", value = "A"),
      @Parameter(name = "size", value = "128")
   })
   List<Integer> legacyA;

  @Type(type = "LegacyArrayUserType",
        parameters =
   {
      @Parameter(name = "prefix", value = "B"),
      @Parameter(name = "size", value = "64")
   })
   List<Integer> legacyB;
  • 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-12T05:38:57+00:00Added an answer on May 12, 2026 at 5:38 am

    I can think of a couple of ways that I would do this.

    1. Create views for the collection information that simulates a normalized table structure, and map it to Hibernate as a collection:

    Assuming your existing table is called primaryentity, I would create a view that’s similar to the following:

    -- untested SQL...
    create view childentity as
    (select primaryentity_id, c1 from primaryentity union
    select primaryentity_id, c2 from primaryentity union
    select primaryentity_id, c3 from primaryentity union
    --...
    select primaryentity_id, c100 from primaryentity)
    

    Now from Hibernate’s perspective, childentity is just a normalized table that has a foreign key to primarykey. Mapping this should be pretty straight forward, and is covered here:

    • http://docs.jboss.org/hibernate/stable/core/reference/en/html/collections.html

    The benefits of this approach:

    • From Hibernate’s point of view, the tables are normalized, it’s a fairly simple mapping
    • No updates to your existing tables

    The drawbacks:

    • Data is read-only, I don’t think your view can be defined in an updatable manner (I could be wrong)
    • Requires change to the database, you may need to create lots of views

    Alternately, if your DBA won’t even let you add a view to the database, or if you need to perform updates:


    2. Use Hibernate’s dynamic model mapping facility to map your C1, C2, C3 properties to a Map, and have some code you your DAO layer do the appropriate conversation between the Map and the Collection property:

    I have never done this myself, but I believe Hibernate does allow you to map tables to HashMaps. I’m not sure how dynamically Hibernate allows you to do this (i.e., Can you get away with simply specifying the table name, and having Hibernate automatically map all the columns?), but it’s another way I can think of doing this.

    If going with this approach though, be sure to use the data access object pattern, and ensure that the internal implementation (use of HashMaps) is hidden from the client code. Also be sure to check before writing to the database that the size of your collection does not exceed the number of available columns.

    The benefits of this approach:

    • No change to the database at all
    • Data is updatable
    • O/R Mapping is relatively simple

    The drawbacks:

    • Lots of plumbing in the DAO layer to map the appropriate types
    • Uses experimental Hibernate features that may change in the future
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this legacy database for which I'm building a custom viewer using Linq
I've got a legacy database with a bunch of idiotically named columns like: some_field_c
I'm working with a legacy database in Oracle and some of my tables have
I am working with a legacy database schema that looks like this: product_table table
I have legacy database in which transaction tables are stored by monthly names. eg.
Being stuck with a legacy database schema that no longer reflects your data model
I have to connect to a legacy postgres database which has ENCODING = 'SQL_ASCII';
I have a legacy database that I'm working on getting ActiveRecord to work with.
I want to add a column to an existing legacy database and write a
I am developing RoR application that works with legacy database and uses ActiveScaffold plugin

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.