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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:09:51+00:00 2026-05-30T15:09:51+00:00

In ORMLite, how can I define a constraint (foreign) to another table, which is

  • 0

In ORMLite, how can I define a constraint (foreign) to another table, which is not linked by it’s integer id, but by any other field, i.e. a varchar/string field, which isn’t the PK.

For example, referring to the ORMLite sample code, where an ‘order’ entity is linked to an ‘account’ entity. In the example, the order is linked to the account by it’s id column (I guess by default), which is the PK.

Instead of setting up the constraint from ‘order.account_id’ to the ‘account.id’ column, how can I set it up from something like ‘order.account_name’ to ‘account.name’ column instead?
I was looking for something like a foreignColumnName annotation, but unfortunately it doesn’t exist, for a one-to-one relationship.

Here’s the java code of the ORMLite examples:

  • Order.java

  • Account.java

I couldn’t find any info in the documentation.

(The reason why I need it is that I have an existing db, not created by ORMLite automatically, which has obviously not been setup properly nor halfway normalized, but I need to work with that existing one, including it’s existing column names and constraints.)

  • 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-30T15:09:52+00:00Added an answer on May 30, 2026 at 3:09 pm

    I was looking for something like a foreignColumnName annotation, but unfortunately it doesn’t exist, for a one-to-one relationship.

    Edit:

    This feature was added to ORMLite in version 4.36. The concept of foreign objects was a new construct at the time. See the javadocs on the field here. To quote:

    public abstract String foreignColumnName

    Name of the foreign object’s field that is tied to this table. This does not need to be specified if you are using the ID of the foreign object which is recommended. For example, if you have an Order object with a foreign Account then you may want to key off of the Account name instead of the Account ID.

    NOTE: Setting this implies foreignAutoRefresh() is also set to true because there is no way to refresh the object since the id field is not stored in the database. So when this is set, the field will be automatically refreshed in another database query.

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

Sidebar

Related Questions

I'm trying to use ServiceStack REST DTO and OrmLite with monoDroid. But I can't
I'm using ormlite for my android-app. But now i have a problem. I have
I am not clever from ORMlite documentation. Is is possible to declare in class,
I have a class which I want to persist with OrmLite and it stores
I'm using ORMLite, with the Table RecentSearch : @DatabaseTable(tableName = LocalStorageConfig.SQL_RECENTS_TABLE_NAME) public class RecentSearch
I have to use an existing Database that I can not change that uses
I have a problem by using the ORMlite framework with more than one table
Having a few problems with Ormlite and Android/Sqlite so any help appreciated. The database
I'm using ormlite for Android and I'm trying to get a multiple column unique-constraint.
Im using ORMLite in my Android app. I need to persist this class, which

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.