Je reçois le message suivant dans la Console: mise en veille prolongée:alter table UserDetails_listofAddress drop constraint FK_a254xtntunnm64c0vo7oha0ol
Je suis incapable de conserver l'ensemble de l'adresse dans la base de données et j'obtiens les exceptions suivantes . comme Hibernate
:
alter table UserDetails_listofAddress
drop constraint FK_a254xtntunnm64c0vo7oha0ol.
Je suis l'exception suivante aussi INFO
:
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException.
Je suis en fournissant le fichier de configuration hibernate , Value object class
, classe qui est censé être maintenu et également la classe de test .
Hibernate fichier de Configuration
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">708477</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="connection.pool_size">10</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping class="com.sanjay.hibernateDTO.UserDetails"/>
</session-factory>
</hibernate-configuration>
UserDetails.java
@Entity
@Table(name = "USER_DETAILSS")
public class UserDetails {
@Id @GeneratedValue(stratégie = GenerationType.AUTO)
private int id d'utilisateur;
private String nom d'utilisateur;
@Embedded
Adresse privée physicaladdress;
@ElementCollection
private Set<Address> listofAddress = new HashSet();
public Set<Address> getListofAddress() {
return listofAddress;
}
public void setListofAddress(Set<Address> listofAddress) {
this.listofAddress = listofAddress;
}
public Address getOfficeAddresss() {
return officeAddresss;
}
public void setOfficeAddresss(Address officeAddresss) {
this.officeAddresss = officeAddresss;
}
public Address getPhysicaladdress() {
return physicaladdress;
}
public void setPhysicaladdress(Address physicaladdress) {
this.physicaladdress = physicaladdress;
}
@Embedded
@AttributeOverrides
({
@AttributeOverride(name = "street", column = @Column(name = "HOME_STREET_NAME")),
@AttributeOverride(name = "state", column = @Column(name = "HOME_STATE_NAME")),
@AttributeOverride(name = "city", column = @Column(name = "HOME_CITY_NAME")),
@AttributeOverride(name = "pincode", column = @Column(name = "HOME_ZIPCODE"))
})
private Address officeAddresss;
@Temporal(TemporalType.TIME)
private Date joinedDate;
public Date getJoinedDate() {
return joinedDate;
}
public void setJoinedDate(Date joinedDate) {
this.joinedDate = joinedDate;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
private String address;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
Classe D'Adresse
@Embeddable
public class Address {
@Column(name="USER_STREET")
private String street;
@Column(name="USER_CITY")
private String city;
@Column(name="USER_STATE")
private String state;
@Column(name="USER_PINCODE")
private String pincode;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}
}
HibernateTest.java
public class HibernateTest {
public static void main(String[] args) {
//TODO Auto-generated method stub
UserDetails user = new UserDetails();
user.setUserName("FirstUser");
user.setJoinedDate(new Date());
user.setAddress("ADDRESS JOINED");
Address addr = new Address();
addr.setCity("Hyderabad");
addr.setPincode("50001");
addr.setState("Telangana");
addr.setStreet("Banjara Hills");
user.getListofAddress().add(addr);
Address homeaddress=new Address();
homeaddress.setCity("NEW CITY");
homeaddress.setPincode("55551");
homeaddress.setState("NEW STATE");
homeaddress.setStreet("NEW STREET");
user.getListofAddress().add(homeaddress);
SessionFactory sf = new Configuration().configure()
.buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
user = null;
session = sf.openSession();
session.beginTransaction();
user = (UserDetails) session.get(UserDetails.class, 1);
System.out.println(user.getUserName());
}
}
SORTIE imprimée dans la console
May 26, 2014 3:56:39 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
May 26, 2014 3:56:39 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
May 26, 2014 3:56:39 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
May 26, 2014 3:56:39 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 26, 2014 3:56:39 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
May 26, 2014 3:56:39 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
May 26, 2014 3:56:39 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/instead. Refer to Hibernate 3.6 Migration Guide!
May 26, 2014 3:56:39 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
May 26, 2014 3:56:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
May 26, 2014 3:56:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/hibernatedb]
May 26, 2014 3:56:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=postgres, password=****}
May 26, 2014 3:56:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
May 26, 2014 3:56:39 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 10 (min=1)
May 26, 2014 3:56:40 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
May 26, 2014 3:56:40 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
May 26, 2014 3:56:40 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
May 26, 2014 3:56:40 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
May 26, 2014 3:56:41 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate:
alter table UserDetails_listofAddress
drop constraint FK_a254xtntunnm64c0vo7oha0ol
- J'ai également eu presque le même problème, et de projet de travail a soudainement cessé de fonctionner et a donné le même message d'erreur d'exception après l'obtention d'un nouveau clone d'un projet. J'avais réussi à le faire fonctionner qu'après le retour de toutes les modifications effectuées par l'IDE, mais ne pouvait pas identifier la raison.
Vous devez vous connecter pour publier un commentaire.
Ces messages consignés n'ont rien à voir avec votre problème.
Le message ci-dessus est vous dire que Hibernate est de recréer votre schéma:
Le message ci-dessus est parce que votre chauffeur ne prend pas en charge JDBC4 lob création
Le vrai problème est là:
Vous avez tout simplement oublié à la fin de la cours d'exécution de la transaction: commit ou rollback.
Donc, à le modifier:
Bien que cela permettra de résoudre votre problème, vous êtes loin d'être terminé. Vous avez encore besoin de:
System.out.println
Session
.Pour plus de détails de la façon dont vous devez gérer les ressources de manière efficace, découvrez la GitHub de mon livre, Haute Performance De Persistance Java.
OMG! Après avoir lutté beaucoup, j'ai eu la Solution de ce problème.
Je suis de l'utilisation d'Hibernate-5 et postgress version 10 et PGSimpleDataSource pour la source de données
simplement Nous avons besoin d'ajouter ci-dessous les propriétés hibernate fichier de propriétés.
De l'environnement.NON_CONTEXTUAL_LOB_CREATION = "hibernate.jdbc.lob.non_contextual_creation"
hibernateProp.mettre de l'Environnement.NON_CONTEXTUAL_LOB_CREATION, true);
il permettra de résoudre les problèmes.