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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:33:30+00:00 2026-06-14T02:33:30+00:00

I have a Question class that contains a list of Answer objects. In my

  • 0

I have a Question class that contains a list of Answer objects.
In my POJOs I represent this in my Question class as:

@ForeignCollectionField 
private ForeignCollection<Answer> answers;

and in my Answer class this relationship is declared as:

@DatabaseField(foreign = true, canBeNull=false)
private Question question;

I had expected that ORMlite would throw an exception if I tried to persist an Answer which referenced a Question that had not yet been persisted to the database. However, this does not appear to happen. I can persist Answer objects as I please without saving the referenced Question objects. I verified the Answers are being saved with no questions being saved by looking in my database using SQLliteBrowser. This breaks my data integrity as when I restart my program the db now contains Answers that reference non existing questions.

Is there any way to enforce this? With my experience in Hibernate it will not allow you to save the Child object without first saving the referenced “Parent” object.

  • 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-14T02:33:31+00:00Added an answer on June 14, 2026 at 2:33 am

    Add the following columnDefinition to your field and it will not allow the object to be created if the foreign ID it references does not exist.

    @DatabaseField(foreign = true, canBeNull=false,
         columnDefinition = "integer references question(id) on delete cascade")
    private Question question;
    

    See also other thread: Creating foreign key constraints in ORMLite under SQLite

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

Sidebar

Related Questions

I have a class that contains a List<> of objects. For this example I
I have a datagrid that displays a list of custom objects. This list contains
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a Question class that has public List property that can contain several
I have a linked list question that stems from this homework prompt I am
Fairly simple question: I have an init method on my class that has the
Given: I have an interface. I have only class that implements that interface. Question:
I have a class called Question that has a property called Type. Based on
I have a design problem: Question class: have a question and answer (String) TextQuestion
I have another question for you. I have a python class with a list

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.