|
|
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
session = sessionFactory.openSession(); session.save(client); session.delete(client); session.close(); Log: Hibernate: insert into Clients (email, password, cli_name, address, inn, kpp, isPhisical, isnew) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: select last_insert_id() Hibernate: insert into Contacts (fio, job_title, phone, client_id) values (?, ?, ?, ?) Hibernate: select last_insert_id() В чем проблема? Вот маппинги: Client <hibernate-mapping> <class name="dao.ClientImp1" table="Clients"> <id name="clientId" type="integer" unsaved-value="null" > <column name="id" sql-type="int" not-null="true"/> <generator class="identity"/> </id> <property name="email" type="string"> <column name="email" sql-type="varchar(50)" length="16" not-null="true"/> </property> <property name="password" type="string"> <column name="password" sql-type="varchar(50)" not-null="true"/> </property> <property name="businessTitle" type="string"> <column name="cli_name" sql-type="varchar(180)" not-null="false"/> </property> <property name="businessAddress" type="string"> <column name="address" sql-type="varchar(240)" not-null="false"/> </property> <property name="clientInn" type="string"> <column name="inn" sql-type="varchar(30)" not-null="true"/> </property> <property name="clientKpp" type="string"> <column name="kpp" sql-type="varchar(9)" not-null="false"/> </property> <property name="isPhisical" type="string"> <column name="isPhisical" sql-type="enum('n','y')" not-null="true"/> </property> <property name="isNew" type="integer"> <column name="isnew" sql-type="tinyint(1)" not-null="false"/> </property> <set name="contacts" cascade="all"> <key column="client_id"/> <one-to-many class="dao.ContactImp1"/> </set> </class> </hibernate-mapping> Contact <hibernate-mapping> <class name="dao.ContactImp1" table="Contacts"> <id name="contactId" type="integer" unsaved-value="null" > <column name="id" sql-type="int" not-null="true"/> <generator class="identity"/> </id> <property name="contactPersonName" type="string"> <column name="fio" sql-type="varchar(50)" length="16" not-null="true"/> </property> <property name="contactPersonJobPosition" type="string"> <column name="job_title" sql-type="varchar(50)" not-null="false"/> </property> <property name="contactPhones" type="string"> <column name="phone" sql-type="varchar(50)" not-null="true"/> </property> <many-to-one name="client" class="dao.ClientImp1" cascade="save-update" column="client_id"/> </class> </hibernate-mapping> ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 12:22 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
поставить session.flush() перед session.close() ? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 12:43 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
Ага, спасибо. Спотыкаюсь на всякой ерунде... Если я правильно понял.. save() и delete() SQL - Запросы закэшировали , а после flush() все выполнились. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 12:57 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 12:57 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
. © .а у них есть подобие autocommit? session.setFlushMode(FlushMode.ALWAYS); - настоятельно не рекомендуется :) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 13:22 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
... а вот и грабли началися! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 17:53 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
Какие грабли, человек забыл flush вызвать!? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 19:28 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
Опять старый спор? Это он не _забыл_ про flush, а еще не _привык_ думать, как настоящий hiberнетчик должон. Вот и грабли. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.05.2005, 22:09 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
andrushokОпять старый спор? Это он не _забыл_ про flush, а еще не _привык_ думать, как настоящий hiberнетчик должон. Вот и грабли. млять. нет слов. какие грабли?? это документация ! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 29.05.2005, 13:17 |
|
||
|
Не работает Session.delete() в Hibernate
|
|||
|---|---|---|---|
|
#18+
Как порядочный юзер. Открываю html reference, ищу delete. Нашел пункт 9.5. Ага, Session.delete() will remove an object's state from the database. Хм.. не удаляется. Да, я согласен, что надо читать всю документацию, чтобы не возникало такого. Но когда хочется сделать простой работающий пример. Документация: 9.5. Deleting persistent objects Session.delete() will remove an object's state from the database. Of course, your application might still hold a reference to it. So it's best to think of delete() as making a persistent instance transient. sess.delete(cat); You may also delete many objects at once by passing a Hibernate query string to delete(). You may now delete objects in any order you like, without risk of foreign key constraint violations. Of course, it is still possible to violate a NOT NULL constraint on a foreign key column by deleting objects in the wrong order. 9.6. Flush From time to time the Session will execute the SQL statements needed to synchronize the JDBC connection's state with the state of objects held in memory. This process, flush, occurs by default at the following points from some invocations of find() or iterate() from net.sf.hibernate.Transaction.commit() from Session.flush() The SQL statements are issued in the following order all entity insertions, in the same order the corresponding objects were saved using Session.save() all entity updates all collection deletions all collection element deletions, updates and insertions all collection insertions all entity deletions, in the same order the corresponding objects were deleted using Session.delete() (An exception is that objects using native ID generation are inserted when they are saved.) Except when you explicity flush(), there are absolutely no guarantees about when the Session executes the JDBC calls, only the order in which they are executed. However, Hibernate does guarantee that the Session.find(..) methods will never return stale data; nor will they return the wrong data. It is possible to change the default behavior so that flush occurs less frequently. The FlushMode class defines three different modes. This is most useful in the case of "readonly" transactions, where it might be used to achieve a (very) slight performance increase. sess = sf.openSession(); Transaction tx = sess.beginTransaction(); sess.setFlushMode(FlushMode.COMMIT); //allow queries to return stale state Cat izi = (Cat) sess.load(Cat.class, id); izi.setName(iznizi); // execute some queries.... sess.find("from Cat as cat left outer join cat.kittens kitten"); //change to izi is not flushed! ... tx.commit(); //flush occurs ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 30.05.2005, 07:39 |
|
||
|
|

start [/forum/topic.php?fid=59&tid=2152288]: |
0ms |
get settings: |
11ms |
get forum list: |
16ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
86ms |
get topic data: |
10ms |
get forum data: |
3ms |
get page messages: |
48ms |
get tp. blocked users: |
2ms |
| others: | 250ms |
| total: | 432ms |

| 0 / 0 |
