Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在控制台中收到以下消息:Hibernate:alter table UserDetails\u listofAddress drop constraint FK\u a254xtntunnm64c0vo7oha0ol_Hibernate - Fatal编程技术网

我在控制台中收到以下消息:Hibernate:alter table UserDetails\u listofAddress drop constraint FK\u a254xtntunnm64c0vo7oha0ol

我在控制台中收到以下消息:Hibernate:alter table UserDetails\u listofAddress drop constraint FK\u a254xtntunnm64c0vo7oha0ol,hibernate,Hibernate,我无法将地址集持久保存到数据库中,并且出现以下异常。类似于休眠: alter table UserDetails_listofAddress drop constraint FK_a254xtntunnm64c0vo7oha0ol. HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

我无法将地址集持久保存到数据库中,并且出现以下异常。类似于休眠:

alter table UserDetails_listofAddress 
    drop constraint FK_a254xtntunnm64c0vo7oha0ol.  
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException.  
<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>
    @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;
    }       
}
我还收到以下异常信息
INFO

alter table UserDetails_listofAddress 
    drop constraint FK_a254xtntunnm64c0vo7oha0ol.  
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException.  
<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>
    @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;
    }       
}
我提供了hibernate配置文件,
Value-object-class
,应该持久化的类以及测试类

<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>
    @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;
    }       
}
休眠配置文件

<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>
    @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;
    }       
}
hibernatest.java

<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>
    @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;
    }       
}
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());
    }
}
控制台中打印的输出

<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>
    @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;
    }       
}
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
2014年5月26日下午3:56:39 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
信息:HCANN000001:Hibernate Commons注释{4.0.4.Final}
2014年5月26日下午3:56:39 org.hibernate.Version日志版本
信息:hh000412:Hibernate核心{4.3.5.Final}
2014年5月26日下午3:56:39 org.hibernate.cfg.Environment
信息:HH000205:从资源hibernate加载的属性。属性:{hibernate.connection.driver\u class=org.h2.driver,hibernate.service.allow\u crawling=false,hibernate.dialogue=org.hibernate.dialogue.h2方言,hibernate.max\u fetch\u depth=5,hibernate.format\u sql=true,hibernate.generate\u statistics=true,hibernate.connection.username=sa,hibernate.connection.url=jdbc:h2:mem:db1;DB\u CLOSE\u DELAY=true,hibernate.bytecode.use\u reflection\u optimizer=false,hibernate.jdbc.batch\u versioned\u data=true,hibernate.connection.pool\u size=5}
2014年5月26日下午3:56:39 org.hibernate.cfg.Environment buildBytecodeProvider
信息:HH000021:字节码提供程序名称:javassist
2014年5月26日下午3:56:39 org.hibernate.cfg.Configuration
信息:HH000043:从资源配置:/hibernate.cfg.xml
2014年5月26日下午3:56:39 org.hibernate.cfg.Configuration getConfigurationInputStream
信息:hh000040:配置资源:/hibernate.cfg.xml
2014年5月26日下午3:56:39 org.hibernate.internal.util.xml.DTDEntityResolver解析实体
警告:HH000223:已识别过时的hibernate命名空间http://hibernate.sourceforge.net/. 使用名称空间http://www.hibernate.org/dtd/ 请参阅Hibernate 3.6迁移指南!
2014年5月26日下午3:56:39 org.hibernate.cfg.Configuration doConfigure
信息:HH000041:配置的会话工厂:null
2014年5月26日下午3:56:39 org.hibernate.engine.jdbc.connections.internal.driverManager连接提供MPL配置
警告:HH000402:使用Hibernate内置连接池(不用于生产!)
2014年5月26日下午3:56:39 org.hibernate.engine.jdbc.connections.internal.driverManager连接ProviderImpl buildCreator
信息:HH000401:在URL[jdbc:p]处使用驱动程序[org.postgresql.driver]ostgresql://localhost:5432/hibernatedb]
2014年5月26日下午3:56:39 org.hibernate.engine.jdbc.connections.internal.driverManager连接ProviderImpl buildCreator
信息:HH000046:连接属性:{user=postgres,password=**}
2014年5月26日下午3:56:39 org.hibernate.engine.jdbc.connections.internal.driverManager连接ProviderImpl buildCreator
信息:HH000006:自动提交模式:错误
2014年5月26日下午3:56:39 org.hibernate.engine.jdbc.connections.internal.driverManager连接提供MPL配置
信息:HH000115:休眠连接池大小:10(最小值=1)
2014年5月26日下午3:56:40 org.hibernate.dialogue.dialogue
信息:HH000400:使用方言:org.hibernate.dialogue.PostgreSqlDialogue
2014年5月26日下午3:56:40 org.hibernate.engine.jdbc.internal.LobCreatorBuilder UseContexturationAllobCreation
信息:HH000424:当createClob()方法引发错误时禁用上下文LOB创建:java.lang.reflect.InvocationTargetException
2014年5月26日下午3:56:40 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
信息:HH000399:使用默认事务策略(直接JDBC事务)
2014年5月26日下午3:56:40 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
信息:HH000397:使用ASTQueryTranslatorFactory
2014年5月26日下午3:56:41 org.hibernate.tool.hbm2ddl.SchemaExport执行
信息:HH000227:正在运行hbm2ddl架构导出
冬眠:
alter table UserDetails\u地址列表
跌落约束FK_a254xtntunnm64c0vo7oha0ol

这些记录的消息与您的问题无关

<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>
    @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;
    }       
}
alter table UserDetails_listofAddress 
drop constraint FK_a254xtntunnm64c0vo7oha0ol.
上面的消息告诉您Hibernate正在重新创建您的架构:

<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>
    @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;
    }       
}
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException.
上面的消息是因为您的驱动程序不支持JDBC4 lob创建

<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>
    @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;
    }       
}
真正的问题在于:

<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>
    @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;
    }       
}
session = sf.openSession();
session.beginTransaction();
user = (UserDetails) session.get(UserDetails.class, 1);
System.out.println(user.getUserName());
您只是忘记了结束当前正在运行的事务:提交或回滚

<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>
    @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;
    }       
}
因此,将其更改为:

<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>
    @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;
    }       
}
Session session = openSession();
session.beginTransaction();

user = (UserDetails) session.get(UserDetails.class, 1);
System.out.println(user.getUserName());

session.getTransaction().commit();
session.close();
虽然这将解决您的问题,但您还远远没有完成。您仍然需要:

<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>
    @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;
    }       
}
  • 使用日志框架而不是
    System.out.println
  • 使用try/finally块结束事务并关闭
    会话

  • 天哪!经过一番努力,我终于找到了解决这个问题的办法。 我使用Hibernate-5和postgress版本10以及PGSimpleDataSource作为数据源 我们只需要在hibernate属性文件中添加以下属性

    <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>
    
        @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;
        }       
    }
    
    Environment.NON\u context\u LOB\u CREATION=“hibernate.jdbc.LOB.NON\u context\u CREATION” hibernateProp.put(Environment.NON_context_LOB_CREATION,true);

    <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>
    
        @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;
        }       
    }
    

    它将解决问题。

    @Vlad Mihalcea:“这是因为您的驱动程序不支持JDBC4 lob创建。”,您提到的驱动程序是什么,请让我知道。检查H2驱动程序jar。我正在使用postgres数据库,那么我为什么要检查H2驱动程序?因为您发布的hibernate方言是H2方言,现在您说我也注意到了postgres异常,所以您最好在@Vlad Mihalcea将其整理出来*****org.hibernate.dialogue.postgresqldialdialogue****这是我正在使用的方言,我也更新了我的JDBC jar,但我仍然收到了错误---“2014年6月1日12:26:40 PM org.hibernate.engine.JDBC.internal.LobCreatorBuilder使用上下文allobcreation信息:HHH000424:禁用上下文LOB创建作为
    <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>
    
        @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;
        }       
    }