首先抱歉.我知道它有很多相同的主题,但也许我的英语不好或者我找不到正确的答案.
我使用乐观锁定@Version注释.我需要从一个表中有一个一行有来自不同表的众多行,我确实插入了这样的:
所以它必须如下所示:
机构(这是我表中的一行(机构))
Run Code Online (Sandbox Code Playgroud)- CreationDate A (this is row from different table(CreationDate) bind with Institution with JoinTable, ManyToMany) - CreationDate B (this is row from different table(CreationDate) bind with Institution with JoinTable, ManyToMany) - CreationDate C (this is row from different table(CreationDate) bind with Institution with JoinTable, ManyToMany)
因此,为了使这个CreationDate具有不同的变化,我决定手动为我想要添加我的CreationDate的特定机构添加id.
我的主要方法类:
CreationDate crdate = new CreationDate();
Institution inst= new Institution();
Set<Institution> instituset = new HashSet<Institution>();
***inst.setInstitutionId(2);***
inst.setNameOfInstitution("MyInstitution");
inst.setTypeName("Education");
instituset.add(inst);
Run Code Online (Sandbox Code Playgroud)
当我想要附加到我的机构的另一行数据时,我在我的代码中添加了用星号标记的行.首先在数据库中插入我的版本行变为一行.
这是我的机构实体:
@Entity
@Table(name="INSTITUTION")
public class Institution implements Serializable{ …Run Code Online (Sandbox Code Playgroud) 在我搜索之前,我知道我的情况不单,但仍然认为我有个别问题.
2013-04-13 12:15:04,980 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [app-context.xml]>
2013-04-13 12:15:05,312 INFO [org.springframework.context.support.GenericXmlApplicationContext] - <Refreshing org.springframework.context.support.GenericXmlApplicationContext@8def5d: startup date [Sat Apr 13 12:15:05 EDT 2013]; root of context hierarchy>
2013-04-13 12:15:05,405 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - <Loading properties file from class path resource [connection.properties]>
2013-04-13 12:15:05,438 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c816a9: defining beans [dataSource,transactionManager,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,contactDao,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,sessionFactory]; root of factory hierarchy>
2013-04-13 12:15:05,452 INFO [org.springframework.jdbc.datasource.DriverManagerDataSource] - <Loaded JDBC driver: com.mysql.jdbc.Driver>
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting …Run Code Online (Sandbox Code Playgroud)