0

I was just trying to make a list display some information based on the information that I selected before

I have

object 1 abstract

and object a, b, c, d, e that extends object 1

listview 1 displays object a, b, c, d, e

and listview 2 displays many objects depending on what item you clicked on list view 1

my problem is that all those objects in listview 2 must be a List<> of type object 1

@Entity
    public static final int TYPE_COFFEE = 0;
    public static final int TYPE_MARKET = 1;
    public static final int TYPE_POST = 2;
    public static final int TYPE_RESTAURANT = 3;
    public static final int TYPE_STORE = 4;

    @PrimaryKey(autoGenerate = true)
    private long id;
    private String image;
    private String establishmentName;
    private String adress;
    public int type;

    public Establishment(long id, String image, String establishmentName, String adress) {
        this.id = id;
        this.image = image;
        this.establishmentName = establishmentName;
        this.adress = adress;
    }
@Dao

    @Query("SELECT * FROM Coffee, Market, Post, Restaurant, Store WHERE type = :type")
    List<Establishment> getEstablishmentByType(int type);
@Place where I want to use that info

        List<Establishment> establishmentList = EstablishmentDB.getInstance(this).getEstablishmentDao().getEstablishmentByType(establishmentType);
        EstablishmentListAdapter adapter = new EstablishmentListAdapter(establishmentList, this);
        establishmentListView.setAdapter(adapter);

  • Your @Query looks way wrong; it’s going to do a join across ALL the tables. If all the different types of Establishment have the same columns, it would be MUCH easier to have a single table. If you really want multiple tables, use UNION ALL, so “Select * from coffee where type = :type UNION ALL select * from market where type= :type UNION ALL .....” – racraman Jul 08 '19 at 04:02
  • hi there first of all thanks for trying to help. As you said I tried redo the query with the UNION ALL and it sais that the establishments do not have the same number of columns witch its true. So I replace the * for the "id" witch was enough but now says "The columns returned by the query does not have the fields [type] in com.packadge.Establishment even though they are annotated as non-null or primitive. Columns returned by the query: [id]" but they do have that field – Pakistanes Master Jul 09 '19 at 18:06
  • Ah, so they are different layouts, and I take it Rstablishment is (or will be) an abstract superclass, yes? Rather than concentrating on the I’d, instead concentrate on getting it working with one type without the UNIONs. When you’ve got thatmapping correctly, then look at the table joining with inheritance using @Discriminator - ev see https://stackoverflow.com/questions/4275517/discriminator-in-inheritancetype-joined – racraman Jul 09 '19 at 20:50
  • Also, Entity polos generally don’t have a constructor, but just the getters and setters. Not sure if that could be the problem, but maybe that error is that when you’re only selecting the id then theres no constructor it can call. – racraman Jul 09 '19 at 21:00

0 Answers0