Я пытаюсь получить данные из RSS-канала и поместить их в таблицу H2. У меня уже есть RSS-канал, но теперь я пытаюсь проверить, действительно ли я могу поместить его в базу данных.
Я пытался изменить конфигурацию моих файлов application.properties или файла hibernate.cfg.xml, но безрезультатно. Сначала я подумал, что, возможно, это соглашение об именах, но я пробовал некоторые варианты или просто добавлял аннотации к классу Entity, чтобы просто видеть, но все равно не работал.
Это файл hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name = "connection.driver_class">org.h2.Driver</property>
<property name = "connection.url">jdbc:h2:mem:testdbt</property>
<property name = "connection.username">sa</property>
<property name = "connection.password"/>
<property name = "hibernate.default_schema">PUBLIC</property>
<!-- JDBC connection pool (use the built-in) -->
<property name = "connection.pool_size">1</property>
<!-- SQL dialect -->
<property name = "dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Disable the second-level cache -->
<property name = "cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name = "hibernate.current_session_context_class">thread</property>
<!-- Echo all executed SQL to stdout -->
<property name = "show_sql">true</property>
<property name = "format_sql">true</property>
<property name = "use_sql_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name = "hbm2ddl.auto">create-drop</property>
<mapping class = "com.csdm.rssfeeder.model.RssFeeder"/>
</session-factory>
</hibernate-configuration>
Это класс сущности:
@Entity
@Table(name = "Feed")
public class RssFeeder {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "TITLE")
private String title;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "PUBLICATION_DATE")
private String publicationDate;
@Column(name = "IMAGE")
private String image;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPublicationDate() {
return publicationDate;
}
public void setPublicationDate(String publicationDate) {
this.publicationDate = publicationDate;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
@Override
public String toString() {
return "RssFeeder{" +
"title='" + title + '\'' +
", description='" + description + '\'' +
", publicationDate='" + publicationDate + '\'' +
", image='" + image + '\'' +
'}';
}
}
Это класс EntityManager:
SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(RssFeeder.class).buildSessionFactory();
Session session = factory.getCurrentSession();
try {
RssFeeder rssFeeder = new RssFeeder();
rssFeeder.setId(1);
rssFeeder.setPublicationDate("fmm");
rssFeeder.setTitle("fmm");
rssFeeder.setImage("fmm");
rssFeeder.setDescription("fmm");
session.beginTransaction();
session.save(rssFeeder);
session.getTransaction().commit();
} finally {
factory.close();
}
}
Это журнал консоли. Я не знаю, почему это показывает? вместо фактических значений в журнале консоли.
2019-07-28 00:24:47.139 WARN 8272 --- [ main] org.hibernate.orm.deprecation : HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
2019-07-28 00:24:47.424 WARN 8272 --- [ main] org.hibernate.orm.connections : HHH10001002: Using Hibernate built-in connection pool (not for production use!)
2019-07-28 00:24:47.427 INFO 8272 --- [ main] org.hibernate.orm.connections : HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:mem:testdbt]
2019-07-28 00:24:47.428 INFO 8272 --- [ main] org.hibernate.orm.connections : HHH10001001: Connection properties: {user=sa, password=****}
2019-07-28 00:24:47.428 INFO 8272 --- [ main] org.hibernate.orm.connections : HHH10001003: Autocommit mode: false
2019-07-28 00:24:47.432 INFO 8272 --- [ main] .c.i.DriverManagerConnectionProviderImpl : HHH000115: Hibernate connection pool size: 1 (min=1)
2019-07-28 00:24:47.436 INFO 8272 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate:
drop table PUBLIC.Feed if exists
Hibernate:
create table PUBLIC.Feed (
ID integer generated by default as identity,
DESCRIPTION varchar(255),
IMAGE varchar(255),
PUBLICATION_DATE varchar(255),
TITLE varchar(255),
primary key (ID)
)
2019-07-28 00:24:47.471 INFO 8272 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7793ad58'
Hibernate:
insert
into
PUBLIC.Feed
(ID, DESCRIPTION, IMAGE, PUBLICATION_DATE, TITLE)
values
(null, ?, ?, ?, ?)
2019-07-28 00:24:47.761 INFO 8272 --- [ main] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'
Hibernate:
drop table PUBLIC.Feed if exists
2019-07-28 00:24:47.770 INFO 8272 --- [ main] org.hibernate.orm.connections : HHH10001008: Cleaning up connection pool [jdbc:h2:mem:testdbt]




Я исправил проблему. У меня была опечатка в файле hibernate.cfg.xml, указывающая на неправильную базу данных.
Я просто изменил свойства на
jdbc:h2:mem:test;DB_CLOSE_DELAY=-1