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

problem getting @ManyToOne working #29

Open
SingingBush opened this issue Dec 29, 2015 · 4 comments
Open

problem getting @ManyToOne working #29

SingingBush opened this issue Dec 29, 2015 · 4 comments
Assignees
Labels

Comments

@SingingBush
Copy link
Collaborator

the following seems to break:

@Entity
@Table("books")
public class Book {
    public:
        @Id
        @Generated
        Uint id;

        @Column("title", 250) @NotNull
        string title;

        @ManyToOne @JoinColumn("author_id") @NotNull
        Person author;
}

@Entity
@Table("people")
public class Person {
    public:
        @Id
        @Generated
        Uint id;

        @Column("name", 50) @NotNull
        string name;
}

when I try to get books by user the program bombs out:

Query q = session
        .createQuery("FROM Book WHERE author=:person")
        .setParameter("person", somePersonObject);
return q.list!Book();
@buggins buggins added the bug label Sep 16, 2016
@buggins buggins self-assigned this Sep 16, 2016
@SingingBush
Copy link
Collaborator Author

I thought I had updated this issue. I have got ManyToOne working, just not as expected. It wasn't clear from the documentation that I had to do:

Query q = session
        .createQuery("FROM Book WHERE author=:personId")
        .setParameter("personId", somePersonObject.id);
return q.list!Book();

@buggins
Copy link
Owner

buggins commented Sep 22, 2016

Strange. It's not expected to work this way

@SingingBush
Copy link
Collaborator Author

I added a test for it in hdtest/source/htestmain.d in this commit to ensure it keeps working as-is:

    writeln("Test retrieving users by group... (ManyToOne relationship)");
    auto qUsersByGroup = sess.createQuery("FROM User WHERE group=:group_id").setParameter("group_id", grp2.id);
    User[] usersByGroup = qUsersByGroup.list!User();
    assert(usersByGroup.length == 2);

@buggins
Copy link
Owner

buggins commented Sep 23, 2016

I think there should be WHERE group.id=:group_id

vnayar pushed a commit to vnayar/hibernated that referenced this issue Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants