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

  • Home
  • SEARCH
  • 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 6857777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:04:16+00:00 2026-05-27T02:04:16+00:00

I am programming an Android app and using ormLite for the database. I want

  • 0

I am programming an Android app and using ormLite for the database.

I want to use the Composite Pattern for some DB items.

I wrote the following code:

Foodstuff

package com.android.droidfridge.data;

import com.j256.ormlite.field.DatabaseField;

public abstract class Foodstuff 
{
    @DatabaseField(id = true, useGetSet = true)
    private String name;

    @DatabaseField(useGetSet = true, foreign = true)
    private Category category;

    @DatabaseField(useGetSet = true)
    private int image;

    public String getName() 
    {
        return name;
    }

    public void setName(String name) 
    {
        this.name = name;
    }

    public Category getCategory() 
    {
        return category;
    }

    public void setCategory(Category category) 
    {
        this.category = category;
    }

    public int getImage() 
    {
        return image;
    }

    public void setImage(int image) 
    {
        this.image = image;
    }
}

Ingredients

package com.android.droidfridge.data;

import java.io.Serializable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "ingredients")
public class Ingredient extends Foodstuff implements Serializable
{
    private static final long serialVersionUID = 5798705059641377421L;

    @DatabaseField(useGetSet = true)
    private int amount;

    @DatabaseField(useGetSet = true)
    private int defaultAmount;

    @DatabaseField(useGetSet = true)
    private float price;

    @DatabaseField(useGetSet = true)
    private BaseUnit unit;

    public float getPrice() 
    {
        return price;
    }

    public void setPrice(float price) 
    {
        this.price = price;
    }

    public BaseUnit getUnit()
    {
        return unit;
    }

    public void setUnit(BaseUnit unit)
    {
        this.unit = unit;
    }

    public int getDefaultAmount() 
    {
        return defaultAmount;
    }

    public void setDefaultAmount(int defaultAmount)
    {
        this.defaultAmount = defaultAmount;
    }

    public int getAmount()
    {
        return amount;
    }

    public void setAmount(int amount)
    {
        this.amount = amount;
    }

    public void add(int additional)
    {
        this.amount += additional;
    }

    public void add_default_amount()
    {
        this.add(this.defaultAmount);
    }
}

Recipe

package com.android.droidfridge.data;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "recipes")
public class Recipe extends Foodstuff implements Serializable
{
    private static final long serialVersionUID = 635229962897104194L;

    @DatabaseField(useGetSet = true)
    private int duration;

    @ForeignCollectionField(eager = true)
    private Collection<Foodstuff> ingredients;

    public int getDuration()
    {
        return duration;
    }

    public void setDuration(int duration)
    {
        this.duration = duration;
    }

    public Collection<Foodstuff> getIngredients() 
    {
        return ingredients;
    }

    public void setIngredients(Collection<Foodstuff> ingredients) {
        this.ingredients = ingredients;
    }

    public Foodstuff getIngredient(Foodstuff ingredient) 
    {
        if(ingredients.contains(ingredient))
        {
            Iterator<Foodstuff> iterator = ingredients.iterator();
            boolean check = true;
            while(check)
            {
                if(iterator.equals(ingredient))
                    return (Foodstuff) iterator;

                if(iterator.hasNext())
                    iterator.next();
                else
                    check = false;
            }
        }

        return null;
    }

    public void addIngredient(Ingredient ingredient)
    {
        ingredients.add(ingredient);
    }

    public void removeIngredient(Foodstuff ingredient)
    {
        ingredients.remove(ingredient);
    }

    public int sizeOfIngredients()
    {
        return ingredients.size();
    }
}

Category
package com.android.droidfridge.data;

import java.io.Serializable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "categories")
public class Category implements Serializable 
{
private static final long serialVersionUID = -2222256865380949570L;

@DatabaseField(id = true, useGetSet = true)
private String name;

public String getName() 
{
    return name;
}

public void setName(String name) 
{
    this.name = name;
}
}

Foodstuffs can be ingredients or recipes. Recipes are ingredients or other recipes. Each ingredient and recipe has a category.

I save each category, ingredient and recipe.
But, when I start my app, the log shows errors as follows:

11-23 21:50:16.493: I/TableUtils(261): creating table 'ingredients'
11-23 21:50:16.513: I/TableUtils(261): executed create table statement changed 1 rows: CREATE TABLE `ingredients` (`unit` VARCHAR , `defaultAmount` INTEGER , `price` FLOAT , `amount` INTEGER , `category_id` VARCHAR , `name` VARCHAR , `image` INTEGER , PRIMARY KEY (`name`) ) 
11-23 21:50:16.603: D/dalvikvm(261): GC_FOR_MALLOC freed 8647 objects / 515488 bytes in 44ms
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261): Unable to create databases, sorry dude!
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261): java.sql.SQLException: Foreign collection object class com.android.droidfridge.data.Foodstuff for field 'ingredients' does not contain a foreign field of class class com.android.droidfridge.data.Recipe
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:345)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:171)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:118)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:97)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl$3.<init>(BaseDaoImpl.java:782)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:782)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:74)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:218)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:53)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.android.droidfridge.data.DatabaseHelper.onCreate(DatabaseHelper.java:35)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.onCreate(OrmLiteSqliteOpenHelper.java:168)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:60)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:286)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.android.droidfridge.ListActivity.createIngredient(ListActivity.java:88)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.android.droidfridge.ListActivity.onCreate(ListActivity.java:45)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.view.View.performClick(View.java:2408)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.view.View$PerformClick.run(View.java:8816)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.os.Handler.handleCallback(Handler.java:587)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.os.Looper.loop(Looper.java:123)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at java.lang.reflect.Method.invokeNative(Native Method)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at java.lang.reflect.Method.invoke(Method.java:521)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 21:50:16.663: E/com.android.droidfridge.data.DatabaseHelper(261):     at dalvik.system.NativeStart.main(Native Method)
11-23 21:50:16.843: I/Database(261): sqlite returned: error code = 1, msg = no such table: categories
11-23 21:50:16.843: W/System.err(261): java.sql.SQLException: Unable to run insert stmt on object com.android.droidfridge.data.Category@44ec4070: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:16.853: W/System.err(261):  at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
11-23 21:50:16.853: W/System.err(261):  at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:117)
11-23 21:50:16.853: W/System.err(261):  at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:341)
11-23 21:50:16.853: W/System.err(261):  at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:288)
11-23 21:50:16.853: W/System.err(261):  at com.android.droidfridge.ListActivity.createIngredient(ListActivity.java:88)
11-23 21:50:16.853: W/System.err(261):  at com.android.droidfridge.ListActivity.onCreate(ListActivity.java:45)
11-23 21:50:16.853: W/System.err(261):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 21:50:16.853: W/System.err(261):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-23 21:50:16.853: W/System.err(261):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-23 21:50:16.853: W/System.err(261):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-23 21:50:16.863: W/System.err(261):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-23 21:50:16.863: W/System.err(261):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-23 21:50:16.863: W/System.err(261):  at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-23 21:50:16.863: W/System.err(261):  at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-23 21:50:16.863: W/System.err(261):  at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-23 21:50:16.863: W/System.err(261):  at android.view.View.performClick(View.java:2408)
11-23 21:50:16.863: W/System.err(261):  at android.view.View$PerformClick.run(View.java:8816)
11-23 21:50:16.863: W/System.err(261):  at android.os.Handler.handleCallback(Handler.java:587)
11-23 21:50:16.863: W/System.err(261):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-23 21:50:16.863: W/System.err(261):  at android.os.Looper.loop(Looper.java:123)
11-23 21:50:16.863: W/System.err(261):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 21:50:16.863: W/System.err(261):  at java.lang.reflect.Method.invokeNative(Native Method)
11-23 21:50:16.873: W/System.err(261):  at java.lang.reflect.Method.invoke(Method.java:521)
11-23 21:50:16.873: W/System.err(261):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 21:50:16.873: W/System.err(261):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 21:50:16.873: W/System.err(261):  at dalvik.system.NativeStart.main(Native Method)
11-23 21:50:16.873: W/System.err(261): Caused by: java.sql.SQLException: inserting to database failed: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:16.883: W/System.err(261):  at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
11-23 21:50:16.883: W/System.err(261):  at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:102)
11-23 21:50:16.883: W/System.err(261):  at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:72)
11-23 21:50:16.883: W/System.err(261):  ... 24 more
11-23 21:50:16.883: W/System.err(261): Caused by: android.database.sqlite.SQLiteException: no such table: categories: , while compiling: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:16.893: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-23 21:50:16.893: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
11-23 21:50:16.893: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-23 21:50:16.893: W/System.err(261):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
11-23 21:50:16.903: W/System.err(261):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
11-23 21:50:16.903: W/System.err(261):  at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
11-23 21:50:16.903: W/System.err(261):  at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:94)
11-23 21:50:16.903: W/System.err(261):  ... 25 more
11-23 21:50:16.903: I/Database(261): sqlite returned: error code = 1, msg = no such table: categories
11-23 21:50:16.903: I/Database(261): [ 11-23 21:50:17.044   261:0x105 I/java.sql.SQLException: queryForOne from database failed: SELECT * FROM `categories` WHERE `nObject Error
11-23 21:50:17.044: I/Database(261): sqlite returned: error code = 1, msg = no such table: categories
11-23 21:50:17.044: W/System.err(261): java.sql.SQLException: Unable to run insert stmt on object com.android.droidfridge.data.Category@44ee01b8: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:117)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:341)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:288)
11-23 21:50:17.053: W/System.err(261):  at com.android.droidfridge.ListActivity.createIngredient(ListActivity.java:88)
11-23 21:50:17.053: W/System.err(261):  at com.android.droidfridge.ListActivity.onCreate(ListActivity.java:46)
11-23 21:50:17.053: W/System.err(261):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 21:50:17.053: W/System.err(261):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-23 21:50:17.053: W/System.err(261):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-23 21:50:17.053: W/System.err(261):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-23 21:50:17.053: W/System.err(261):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-23 21:50:17.053: W/System.err(261):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-23 21:50:17.053: W/System.err(261):  at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-23 21:50:17.053: W/System.err(261):  at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-23 21:50:17.053: W/System.err(261):  at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-23 21:50:17.053: W/System.err(261):  at android.view.View.performClick(View.java:2408)
11-23 21:50:17.053: W/System.err(261):  at android.view.View$PerformClick.run(View.java:8816)
11-23 21:50:17.053: W/System.err(261):  at android.os.Handler.handleCallback(Handler.java:587)
11-23 21:50:17.053: W/System.err(261):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-23 21:50:17.053: W/System.err(261):  at android.os.Looper.loop(Looper.java:123)
11-23 21:50:17.053: W/System.err(261):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 21:50:17.053: W/System.err(261):  at java.lang.reflect.Method.invokeNative(Native Method)
11-23 21:50:17.053: W/System.err(261):  at java.lang.reflect.Method.invoke(Method.java:521)
11-23 21:50:17.053: W/System.err(261):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 21:50:17.053: W/System.err(261):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 21:50:17.053: W/System.err(261):  at dalvik.system.NativeStart.main(Native Method)
11-23 21:50:17.053: W/System.err(261): Caused by: java.sql.SQLException: inserting to database failed: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:102)
11-23 21:50:17.053: W/System.err(261):  at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:72)
11-23 21:50:17.053: W/System.err(261):  ... 24 more
11-23 21:50:17.053: W/System.err(261): Caused by: android.database.sqlite.SQLiteException: no such table: categories: , while compiling: INSERT INTO `categories` (`name` ) VALUES (?)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
11-23 21:50:17.073: W/System.err(261):  at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
11-23 21:50:17.073: W/System.err(261):  at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:94)
11-23 21:50:17.073: W/System.err(261):  ... 25 more
11-23 21:50:17.073: I/Database(261): sqlite returned: error code = 1, msg = no such table: categories
11-23 21:50:17.073: I/Database(261): [ 11-23 21:50:17.083   261:0x105 I/java.sql.SQLException: queryForOne from database failed: SELECT * FROM `categories` WHERE `nObject Error
11-23 21:50:17.083: I/Database(261): sqlite returned: error code = 1, msg = no such table: categories
11-23 21:50:17.083: E/Recipe(261): java.sql.SQLException: queryForOne from database failed: SELECT * FROM `categories` WHERE `name` = ?

Question:

  • Why can I not create the category database?
  • Is there an error in my recipe class in the ingredients attribute?
  • 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-27T02:04:17+00:00Added an answer on May 27, 2026 at 2:04 am

    The error that ORMLite is logging is trying to provide the information to help you solve the problem:

    SQLException: Foreign collection object class com.android.droidfridge.data.Foodstuff
        for field 'ingredients' does not contain a foreign field of class
        class com.android.droidfridge.data.Recipe
    

    Your Recipe class contains the following field:

    @ForeignCollectionField(eager = true)
    private Collection<Foodstuff> ingredients;
    

    If you recipe has ingredients then there has to be a foreign field in Foodstuff for the Recipe that “owns” it. This allows ORMLite to do something like:

    SELECT * FROM foodstuff WHERE recipe_id = id;
    

    For example, if you have an Account that has a number of Orders then each of the Order objects should have a foreign Account field. Here are the documentation for foreign collections.

    Instead, if you are going to have a recipe include ingredients that other recipes are going to use then I think what you need is a “join table” as opposed to a foreign collection. Take a look at the “Many To Many” example which uses a join table.

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

Sidebar

Related Questions

I want to learn some programming for my android phone. I was successful doing
I'm abit new to programming Android App's, however I have come across a problem,
I am a complete Android programming newbie. I have completed some tutorial examples like
I've been programming with Java for Android quite some while now. Since performance is
I am programming an Android tablet app. It communicates via UDP messages (13 bytes
I'm trying to make an android app (I'm new in the Android programming world),
I just started programming for android. I'm using a tab based layout in my
I am new to android programming and it's been some years since I have
I have a activity that I want to rotate. I use the following in
this is my first Android app and I'm trying to use Sockets to send

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.