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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:48:05+00:00 2026-06-03T06:48:05+00:00

I have implemented a db which is consisted of Article and Fruit tables, with

  • 0

I have implemented a db which is consisted of Article and Fruit tables, with the following specifications:

create table Fruit
(
ART_ID            bigint,
FRU_ID          bigint not null auto_increment,
FRU_FROZEN   varchar(15),
primary key(FRU_ID)
);

# Implemented

create table Article
(
ART_ID            bigint,
ART_NAME         varchar(10) not null,
ART_COST   varchar(10) not null,
primary key(ART_ID)
);

alter table Fruits add constraint FK_FRUIT_ARTICLE foreign key (ART_ID)
references Article (ART_ID) on delete restrict on update restrict;

and with following class entities :
Article.java

@Entity      
@Table(name = "Article")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Article implements Serializable
 {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Basic(optional = false)
@Column(name = "ART_ID")
private Long id;

@Basic(optional = false)
@Column(name = "ART_NAME")
private String name;

@Basic(optional = true)
@Column(name = "ART_COST")
private String cost; 

// constructors, getters and setters

Fruit.java

@Entity
@Table(name="Fruit")
public class Fruit extends Article{


@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "FRU_ID")
private long fruitID;

@Basic(optional = false)
@Column(name = "FRU_FROZEN")
private String fruitFrozen;

// constructors, getters and setters

Now, my problem is how to have ID in Article and in Fruit, if I keep it this way, it throws me exception that sub-class must not contain IDClass because it will result with multiple ID’s. Any help is appreciated. Thanks in advance.

  • 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-06-03T06:48:07+00:00Added an answer on June 3, 2026 at 6:48 am

    It means what it says, an Entity cannot have two IDs.

    Consider the operation

    entityManager.find(Article.class, 1l);
    

    How is it supposed to know which one to return if there are two articles (an article and a fruit) that both have id 1?

    If your tables need to each have IDs, entity inheritance is not an appropriate solution. Consider putting the common elements in an @MappedSuperclass instead.

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

Sidebar

Related Questions

I have the following tricky problem: I have implemented a (rather complicated) class which
I have a simple lookup table, which consists of the following structure: int |
We have implemented webservice which generates xml response. I am facing issue while invoking
I have implemented an App which uses SQLite database, now if I run the
I have implemented a custom ActionMapper which obtains the locale from the URI (the
I have implemented a small Windows Service which runs every 9 minutes and writes
In my WCF service I have implemented a custom encoder which inherits from System.ServiceModel.Channels.MessageEncoder
I have a generic interface IConstrained which is implemented by the generic Constrained class.
I have one desktop application which was implemented in C#. This app uploads file
I have a TabActivity implemented for my project which is running fine up to

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.