Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to join two table? #139

Open
iobsessu opened this issue Apr 21, 2022 · 2 comments
Open

how to join two table? #139

iobsessu opened this issue Apr 21, 2022 · 2 comments

Comments

@iobsessu
Copy link

iobsessu commented Apr 21, 2022

now, i have a User object and a Role object , it look like this:

class User {
    private int id;
    private String username;
    private int roleId;
}
class Role {
    private int id;
    private String roleName;
}

i wanna know, how can i serialize it to

 {
    id: 10,
    name: "Jack",
    roleId: 20,
    roleName: "admin"
}

instead of

{
    id: 10,
    name: "Jack,
    role: {
        id: 20,
        roleName: "admin"
    }
}
@pengcao1
Copy link

  • First, u should implement your raw sql code like below

  • Second, u implement the multi-table join query with QueryBuilder

  • First step

SELECT
	n.id ,
	n.title ,
	ti.tagName 
from
	TableN n
join TTableN twn on
	twn.note_id = n.id
join TTableI ti on
	ti.id = twn.tagInfo_id 
where ti.tagName ="customize1"  limit 1 offset 2;
  • Second step
        QueryBuilder<TableN, Long> tableNQuery = DatabaseUtils.initialiseDaoWithLong(TableN.class).queryBuilder();
        QueryBuilder<TTableN , Long> ttableNQuery = DatabaseUtils.initialiseDaoWithLong(TTableN .class).queryBuilder();
        QueryBuilder<TTableI , Long> ttableIQuery = DatabaseUtils.initialiseDaoWithLong(TTableI .class).queryBuilder();
 
        ttableNQuery .join(ttableIQuery );

        tableNQuery .join(ttableNQuery );
        tableNQuery .distinct()
        .offset(Const.Note.PAGE_SIZE * (pageNo - 1)).limit(Const.Note.PAGE_SIZE)
        .orderBy("updateTime", false)
        .where().eq("inTrash", false)
        .and().eq("stuId", stuId)
        .query();

@j256
Copy link
Owner

j256 commented Jul 15, 2022

The short answer is that you can't without a lot of customization. Unfortunately, ORMLite right now does not support composite objects like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants