所有
我正在评估Hibernate 4(4.1.0)和Spring 3(3.1.0)中出现的Multi-Tenancy功能,但是无法使用HibernateTransaction设置.我已经定义了如下设置.
LocalSessionFactoryBean:
@org.springframework.context.annotation.Configuration
public class Configuration {
@Inject private DataSource dataSource;
@Inject private MultiTenantConnectionProvider multiTenantConnectionProvider;
@Bean
public LocalSessionFactoryBean sessionFactory() throws IOException{
LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setPackagesToScan("com");
bean.getHibernateProperties().put("hibernate.multi_tenant_connection_provider", multiTenantConnectionProvider);
bean.getHibernateProperties().put("hibernate.multiTenancy", "SCHEMA");
bean.getHibernateProperties().put("hibernate.tenant_identifier_resolver", new CurrentTenantIdentifierResolverImpl());
bean.setConfigLocation(new ClassPathResource("/hibernate.cfg.xml"));
return bean;
}
}
Run Code Online (Sandbox Code Playgroud)
Configuration.xml:
<context:component-scan base-package="com.green" />
<context:annotation-config />
<!-- Enable annotation style of managing transactions -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- Declare a datasource that has pooling capabilities -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" p:driverClass="${app.jdbc.driverClassName}"
p:jdbcUrl="${app.jdbc.url}" p:user="${app.jdbc.username}" p:password="${app.jdbc.password}"
p:acquireIncrement="5" p:idleConnectionTestPeriod="60" …Run Code Online (Sandbox Code Playgroud) 我有桌子
+-------------------+----------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+----------------+------+-----+---------------------+-----------------------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| runtime_id | bigint(20) | NO | MUL | NULL | |
| place_id | bigint(20) | NO | MUL | NULL | |
| amended_timestamp | varchar(50) | YES | | NULL | |
| applicable_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| schedule_time …Run Code Online (Sandbox Code Playgroud) 我偶然发现了这段代码,以便在美国东部时间获得夏令时.它似乎工作正常,当在互联网上检查时显示在提供当前时间在美国东部时间夏令时的网站.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("EST5EDT"));
System.out.println(dateFormat.format(new Date()));
Run Code Online (Sandbox Code Playgroud)
我只是想确认一下,有没有人之前使用过这样的东西,或者有更好的方法来实现同样的目标.由于约束我无法使用Joda库.
提前致谢.
我有如下实体
类ProgressNote
@Entity
public class ProgressNote implements Serializable{
@Id
private NotesKey notesKey = new NotesKey();
private Set<PatientObjective> patientObjectives;
public NotesKey getNotesKey() {
return notesKey;
}
public void setNotesKey(NotesKey notesKey) {
this.notesKey = notesKey;
}
@OneToMany(fetch=FetchType.LAZY)
@Access(AccessType.PROPERTY)
@JoinColumns({
@JoinColumn(name="noteNumber",referencedColumnName="noteNumber"),
@JoinColumn(name="ddate",referencedColumnName="ddate"),
@JoinColumn(name="patient_id",referencedColumnName="patient_id")
})
public Set<PatientObjective> getPatientObjectives() {
return patientObjectives;
}
public void setPatientObjectives(Set<PatientObjective> patientObjectives) {
this.patientObjectives = patientObjectives;
}
}
Run Code Online (Sandbox Code Playgroud)
类NotesKey
@Embeddable
public class NotesKey implements Serializable{
private Byte noteNumber;
@Temporal(javax.persistence.TemporalType.DATE)
@Column(name="ddate")
private Date noteDate;
private Patient patient;
public Byte getNoteNumber() { …Run Code Online (Sandbox Code Playgroud) 所有
我安装了最新的Redis 2.4.16并尝试将其Pub/Sub系统与java一起使用.我每隔一秒就给一个频道发一条消息.Publisher没有问题,但Subscriber与邮件崩溃
例外:
redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context
at redis.clients.jedis.Protocol.processError(Protocol.java:59)
at redis.clients.jedis.Protocol.process(Protocol.java:66)
at redis.clients.jedis.Protocol.read(Protocol.java:131)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:206)
at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:88)
at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:83)
at redis.clients.jedis.Jedis.subscribe(Jedis.java:1971)
at com.jedis.test.JedisSub$1.run(JedisSub.java:22)
at java.lang.Thread.run(Thread.java:680)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
出版商:
final Jedis jedis = new Jedis("localhost");
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(10);
newFixedThreadPool.submit(new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
jedis.publish("CC", new Date().toString());
}
}
});
Run Code Online (Sandbox Code Playgroud)
订户:
JedisPool jedisPool = new JedisPool(poolConfig,"localhost", 6379, 100);
final …Run Code Online (Sandbox Code Playgroud)