I have two hibernate classes: a base class and an extended class that contains other fields. (These fields are mapped by other tables.)

For example, I have:

@[email protected](name="Book")public class A {private String ID; private String Name; // ...}@[email protected](name="Book")public class B extends A {public String node_ID; // ...}public class Node {public String ID; // maps to B.node_ID // ...}

How to map this in Hibernate? The hibernate documentation declares three types of inheritance configurations: one table per class, one table with type columns and one join table-none of them apply here.

The reason I need to do this is because class A comes from a common framework that is reused in multiple projects, and class B (and Node) are extensions specific to one project-they will no longer be used. In the future, I may have A class C with house_ID or other fields.

Edit: If I try the above pseudo code configuration (two entities are mapped to the same table) I get the error that the DTYPE column does not exist. HQL has a place where"add DTYPE="A".

Solution:

This can be achieved by mapping @DiscriminatorColumn and @DiscriminatorValue to the same value of both classes; this can come from any column you use with the same data, regardless of the type (not sure if it is used with a null value).

These classes should look like this:

@[email protected](name="Book")@Inheritance(strategy=InheritanceType.SINGLE_TABLE)@DiscriminatorColumn(name="published")@DiscriminatorValue(value="true")public class A {private String ID; private String Name; // ...}@[email protected](name="Book")@DiscriminatorValue(value="true")public class B extends A {public String node_ID; // ...}

java-Mapping multiple classes to tables in Hibernate without a DTYPE column Related posts

  1. php-multiple LEFT JOINS and multiple COUNT()

    So I am developing a website with a large number of database relationships, because I am still a bit new to query relational databases, so I am a little struggling. So I have a few tables from which I am trying to get relevant data. I will not enter the entire database, Because it is very large, I a ...

  2. javascript-prevent multiple clicks to submit multiple ajax

    I have a WordPress blog running this jQuery code that allows users to click on bookmark links to save posts as bookmarks. Each post displays a total bookmark counter, as shown below: "Bookmarked(5)". Although this code works, as long as If someone clicks on the bookmark link multiple times, it will record multiple clicks, and then save the same post as multiple bookmarks. When the user clicks the bookmark link again to try to delete the bookmark, it will register multiple clicks again, counter S ...

  3. multiple applications in multiple pages of javascript-Aurelia

    I'm developing using PHP (Phalcon), MySQL & jQuery. It is not based on API, although API can be used in some aspects. The date in the stack is too short due to the fact that the project was first prototyped a few years ago, since I will not The reason why I'm bored, it takes years to enter the p ...

  4. c#-copy(multiple) files to multiple locations

    I want to use C# (.NET 4.5) to copy a set of files to multiple locations (for example, copy the contents of a folder to 2 usb drives connected to the computer). Is there a better way than just using a foreach loop and File.Copy More efficient way?Struggling to find a (possible) solution.My first tho ...

  5. python recursively realize the merging of multiple files under multiple folders

    import osimport chardetpath=r''def func(path): size_sum = 0 name_lst = os.listdir(path) for name in name_lst: path_abs = os.path.join(path,name) if os.path.isdir(path_abs) : size = func(path_abs) size_sum += size else: size_sum += os.path.getsize(path_abs) if'.txt' in path_abs: # with open(path_abs, ...

  6. java-multiple conditions and multiple locks

    For a specific thread-safe data structure, I need to protect access to the central data structure (i.e. byte array). In this case, I choose to use ReentrantLocks because of its fairness policy and advanced features that create multiple conditions.The conditions for concurrency are complex, as shown below:> The central byte array must be exclusively protected (i.e. one thread at a time). > The two access methods (foo and bar) must be able to run concurrently (if they try to access the centr ...

  7. python-Split multiple separator columns into multiple columns

    I have a file with 9 columns. One column holds strings like thisUnique3:107912234-107912321(-)4:107913333-107913322(+)Y:222002110-221002100(+)MT:34330044-343123232(-)X:838377373-834121212(+)~400,000 rows, different strings. How to divide it into 4 different columns in the same df, if there is only o ...

  8. python-multiple terminals, multiple commands, lxterminal

    I am using Python. When writing a script, I am trying to use os.system() to open a new terminal, create new tabs and run different commands in each corresponding tab (they seem to run at the same time).I am familiar with gnome-terminal because it is what I used in the past, but the system I am using, Raspberry Pi (Raspbian), uses lxterminal.I always useos.system("gnome-terminal --tab -e'command1' --tab -e'command2'")Success, but I don't know how to reproduce these results with lxterminal. So, ba ...

  9. Python: "Multiple" multiple parameters in a function

    I am a Python newbie, but I know that I can use *args to allow a variable number of multiple parameters in a function.This script looks for words in any number of string*sources:def find(word, *sources): for i in list(sources): if word in i: return Truesource1 ="This is a string"source2 ="This is Wo ...

  10. c# - asp.net multiple upload with multiple fileupload controls

    I'm working on a small project with multiple file uploads.At the beginning the user has a fileupload control and a small image called fileuploadadder.Every time the user clicks on the fileuploadadder, a clone of the first fileupload control is added to the page with jquery. The id of the fileupload ...

  11. php-Search multiple items in multiple columns

    I have 6 choices in the form. I want to search for those in MYSQL DB 6. If I only use one, I can retrieve the results, for example:$result = mysql_query("SELECT * FROM wsinmuebles WHERE Property_Type LIKE'%{$_POST['Property_Type']}%'");But when I tried more, I got no results!$result = mysql_query("S ...

  12. Javamap operation method

    Javamap operation methodpackage basic;import java.util.HashMap;import java.util.Map;public class MapDemo {public static void main(String[] args) {map instantiationMap maps = new HashMap<>();Add elementmaps.put("A", 10); maps.put("B", 20); maps.put("C", 30); maps.put("D", 40); maps.put("E", 50) ...

  13. javascript-Paste multiple numbers in multiple input fields

    I have a form on my website that uses 6 input fields. Site visitors only need to enter a 6-digit code in these 6 boxes. The problem is that they will get a 6-digit code, and ideally Allow them to simply copy the 6-digit code we sent to them into these input fields, just paste into the first input fi ...

  14. javascript – WrapAll() on multiple classes with multiple appearances

    Let's say this is my htmlNow I want to pack .product-thumbnail and .product-price inlike this ...

  15. JavaMap in-depth study

    Java Map Collection Deep LearningFrom: Java Junior Code Farmer Website: https://www.cnblogs.com/lzq198754/p/5780165.html ...

  16. replace multiple characters with corresponding multiple characters in php?

    I want to replace multiple characters in a string with other characters, such as < to a, > to b, ! to c, $ to d, etc. I want to achieve this by using preg_replace in PHP. I can do this in just one line Do this in code, or should I break the string, create the array and then replace it?Solution ...

Recent Posts

  1. c# - why boolean variable always reset to false;

    I have declared a boolean variable at the top of the class, when the radio button is selected on the page, the variable is set to true, but when the page is reloaded, the variable is reset to false. One way I handle this is to use static keyword, but I'm not sure if this is the best way to handle th...

  2. Use canvas todataurl to generate c#image objects

    How to create a Bitmap or Image object using the code generated by the canvas.toimageurl() method?The string is as follows: data: image / jpeg; base64,/ 9j / 4AAQSkZJRgABAQA…Best answer:>A small amount of Regex >A bit of Convert.FromBase64String >Bake with MemoryStream.ctor taking a byte array >Add Bitmap .ctor taking a stream >Serve hotThe sample code is just for fun:using System; using System.Drawing; using System.IO; using System.Text.RegularExpressions; using System.Windows.Fo...

  3. java-the difference between Hibernate and Hibernate JPA

    I found a lot of similar questions> Difference between Hibernate library and Hibernate JPA library > What's the difference between JPA and Hibernate? > similarity and difference between jpa and hibernateBut no one answered my next question. What is the difference between the classic hibernate method implemented using org.hibernate.SessionFactory and JPA javax.persistence.EntityManager? I heard that this JPA implementation uses org.hibernate.SessionFactory and works like a wrapper, is it...

  4. Java Reactor: How to generate Flux from stdin?

    I want to read user generated messages from stdin asynchronously. Something like:Flux.from(stdinPublisher()) .subscribe(msg -> System.out.println("Received:"+ msg));So how to implement such stdin publisher here?Solution:It's easy. Sorry to bother :)import java.util.Scanner;import lombok.extern.sl...

  5. Week 7 Programming Summary

    work headThe function of fun is to change the last letter of each word in the string pointed to by p to uppercase. ("word"here refers to a string separated by spaces).Function interface definition:void fun( char *p );where p is the parameter passed in by the user. The function changes the last lette...

  6. PHP compare two-dimensional arrays

    I want to know how to compare the values of two two-dimensional arrays.First arrayArray 1 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => b ) [2] => Array ( [0] => c ) }the secondArray 2 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => d ) [2] => Array ( [0] => e ) }I need to make my loop to compare arrays and check the matched values. In my example, array1[0][0] = a matches array2[0][0] = a. If it matches, php will output some html.My foreach loopfor...

  7. Python03-04

    I said so much nonsense in the previous blog, now let’s dry the whole thing. 1. The value-based memory management method adopted by python, if you assign the same value to different variables, there is only one copy of this value in the memory, and multiple variables will point to the same address.>>> x=8 >>> id(x) 1626762480 >>> y=8 >>> id(8) 1626762480 >>> x=[1,2,3] >>> id(x[0]) 1626762256 >>> id(x[1]) 1626762288 >>>2. The...

  8. javascript-How to change the text of the radio button

    I have a radio button that needs to be dynamically updated from user input, but the normal .val(), .text() and .html() will not work properly. How to change the text of the radio button using jQuery or pure JavaScript?Solution:The radio button has no text associated with it.But if you have a tag tag/span tag next to the radio option. Then you can use .next to access the element and change its text/htmlDEMOHTML:Option 1EitherOption 1JS:var $label = $('input[type=radio]').next(); $label.text('Opti...

  9. python - sort dictionary alphabetically when key is a string (name)

    First off, I know there are a lot of posts about lexicographical sorting, but I couldn't find one that exactly fits my situation - I just don't understand the sorted(...lambda) stuff - so here goes.Using Python 3.x I have a dictionary like this:dictUsers[Name] = namedTuple(age, address, email, etc.....

  10. Programming Practice Questions Practice Notes-①

    hex conversion problem1. HexadecimalFirst analyze this question, two main points, one is to change the hexadecimal string to a decimal integer, and the second is to traverse the entire string to find the substring starting with 0x.The topic is relatively simple, go directly to part of the codeHexade...