powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / hibernate
4 сообщений из 4, страница 1 из 1
hibernate
    #37735357
AndreyUB
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Добрый всем вечер, есть такой sql
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
create table test (
   id                   int                  identity,
   f_id                 int                  not null,
   f_id3                int                  not null,
   test                 varchar(255)         not null,
   constraint PK_TEST primary key (id)
)
go
create table test2 (
   id2                  int                  identity,
   test2                varchar(255)         not null,
   constraint PK_TEST2 primary key (id2)
)
go
create table test3 (
   id                   int                  identity,
   id3                  int                  not null,
   test3                varchar(255)         not null,
   constraint PK_TEST3 primary key (id)
)
go
create unique index Index_id3 on test3 (
id3 ASC
)
go
alter table test
   add constraint FK_TEST_REFERENCE_TEST2 foreign key (f_id)
      references test2 (id2)
go
alter table test
   add constraint FK_TEST_REFERENCE_TEST3 foreign key (f_id3)
      references test3 (id3)
go
insert into test2 values('test21')
insert into test2 values('test22')
insert into test2 values('test23')

insert into test3 values(9, 'test31')
insert into test3 values(11, 'test32')
insert into test3 values(13, 'test33')

insert into test(f_id, f_id3, test) values(1, 9, 'test11' )
insert into test(f_id, f_id3, test) values(2, 11, 'test12' )
insert into test(f_id, f_id3, test) values(3, 13, 'test13' )
insert into test(f_id, f_id3, test) values(1, 13, 'test13' )
insert into test(f_id, f_id3, test) values(2, 11, 'test12' )
insert into test(f_id, f_id3, test) values(3, 9, 'test11' )

select t.*, t2.*, t3.*
from test t
inner join test2 t2 on t.f_id = t2.id2
inner join test3 t3 on t.f_id3 = t3.id3


и 3 класса
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
@Entity
public class test implements Serializable {
    
   @Id
   @Column(name="id", nullable=false, unique=true)
   private Integer id;
   public Integer getId(){
     return this.id;
   }
   public void setId(Integer id_){
     this.id = id_;
   }
   
    @OneToOne()
    @JoinTable(name="test2",
               joinColumns = @JoinColumn( name="id2"),
               inverseJoinColumns = @JoinColumn( name="f_id"))
    private test2 f_id;
    public test2 getF_id(){
      return this.f_id;
    }
    public void setF_id(test2 f_id_){
      this.f_id = f_id_;
    }
    
    @OneToOne
    @JoinTable(name="test3",
               joinColumns = @JoinColumn( name="id3"),
               inverseJoinColumns = @JoinColumn( name="f_id3"))
    private test3 f_id3;
    public test3 getF_id3(){
      return this.f_id3;
    }
    public void setF_id3(test3 f_id3_){
      this.f_id3 = f_id3_;
    }
    
    @Column(name="test", length=255, nullable=false)
    private String test;
    public String getTest(){
      return this.test;
    }
    public void setTest(String test_){
      this.test = test_;
    }
}

@Entity
public class test2 implements Serializable {
    
   @Id
   @Column(name="id2", nullable=false, unique=true)
   private Integer id2;
   public Integer getId2(){
     return this.id2;
   }
   public void setId2(Integer id2_){
     this.id2 = id2_;
   }
   
   @Column(name="test2", length=255, nullable=false)
   private String test2;
   public String getTest2(){
     return this.test2;
   }
   public void setTest2(String test2_){
     this.test2 = test2_;
   }
}

@Entity
public class test3 implements Serializable {
    
   @Id
   @Column(name="id", nullable=false, unique=true)
   private Integer id;
   public Integer getId(){
     return this.id;
   }
   public void setId(Integer id_){
     this.id = id_;
   }
   
    @Column(name="id3", nullable=false, unique=true)
    private Integer id3;
    public Integer getId3() {
        return id3;
    }
    public void setId3(Integer id3) {
        this.id3 = id3;
    }

    @Column(name="test3", length=255, nullable=false)
    private String test3;
    public String getTest3() {
        return test3;
    }

    public void setTest3(String test3) {
        this.test3 = test3;
    }
}



хочу сделать так
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
      private List<test> test_;
      ...
      this.test_ = this.apputil.getSessionMSSQL2().createSQLQuery("select t.*, t2.*, t3.* "
                                                               + " from test t "
                                                               + " inner join test2 t2 on t.f_id = t2.id2"
                                                               + " inner join test3 t3 on t.f_id3 = t3.id3")
                            .addEntity("t", test.class)
                            .addJoin("t2", "t.f_id")
                            .addJoin("t3", "t.f_id3")
                            .list();


валится с ошибкой
Код: java
1.
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on request.bean.test.f_id3 references an unknown entity: request.bean.test3


вопрос, что я делаю не так, спасибо за помощь
...
Рейтинг: 0 / 0
hibernate
    #37735409
AndreyUB
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
С первой ошибкой разобрался, выплыла вторая, при выполнении запроса, валится так
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [request.bean.test3#9]

Результат запроса такой, что ему не нравится

id	fid	fid3	test	id2	test2	id	id3	test3
1	1	9	test11	1	test21	1	9	test31
2	2	11	test12	2	test22	2	11	test32
3	3	13	test13	3	test23	3	13	test33
4	1	13	test13	1	test21	3	13	test33
5	2	11	test12	2	test22	2	11	test32
6	3	9	test11	3	test23	1	9	test31
...
Рейтинг: 0 / 0
hibernate
    #37735547
забыл ник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
авторCaused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [request.bean.test3#9]
А ошибку читать не пробовали? В классе test3 нет сущности с id=9, что запрос и показывает
...
Рейтинг: 0 / 0
hibernate
    #37735704
AndreyUB
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
забыл ник,
ошибку я читал, только объединение мне необходимо сделать не по id, а вот так
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
@Entity
public class test implements Serializable {
...
    @OneToOne
    @JoinTable(name="test3",
               joinColumns = @JoinColumn( name="id3"),
               inverseJoinColumns = @JoinColumn( name="f_id3"))
    private test3 f_id3;
    public test3 getF_id3(){
      return this.f_id3;
    }
    public void setF_id3(test3 f_id3_){
      this.f_id3 = f_id3_;
    }


или hibernate так не поймет и можно не мучаться
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / hibernate
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]