Using Intellij i've connected to an oracle database, added persistency framework and generated persistence mapping by database schema
package springoraclesql.demo.domain;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Book {
private long bookId;
private String bookName;
private String bookAuthor;
private Long bookPrice;
@Id
@Column(name = "BOOK_ID")
public long getBookId() {
return bookId;
}
public void setBookId(long bookId) {
this.bookId = bookId;
}
@Basic
@Column(name = "BOOK_NAME")
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
@Basic
@Column(name = "BOOK_AUTHOR")
public String getBookAuthor() {
return bookAuthor;
}
public void setBookAuthor(String bookAuthor) {
this.bookAuthor = bookAuthor;
}
@Basic
@Column(name = "BOOK_PRICE")
public Long getBookPrice() {
return bookPrice;
}
public void setBookPrice(Long bookPrice) {
this.bookPrice = bookPrice;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Book book = (Book) o;
if (bookId != book.bookId) return false;
if (bookName != null ? !bookName.equals(book.bookName) : book.bookName != null) return false;
if (bookAuthor != null ? !bookAuthor.equals(book.bookAuthor) : book.bookAuthor != null) return false;
if (bookPrice != null ? !bookPrice.equals(book.bookPrice) : book.bookPrice != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (bookId ^ (bookId >>> 32));
result = 31 * result + (bookName != null ? bookName.hashCode() : 0);
result = 31 * result + (bookAuthor != null ? bookAuthor.hashCode() : 0);
result = 31 * result + (bookPrice != null ? bookPrice.hashCode() : 0);
return result;
}
}
I've added the Oracle jdbc and my persistence.xml
under java/META-INF looks like this`
<persistence-unit name="NewPersistenceUnit">
<class>springoraclesql.demo.domain.Book</class>
<properties>
<property name="toplink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="openjpa.ConnectionDriverName" value="oracle.jdbc.OracleDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
My application.properties looks like this
oracle.dbsource.url=jdbc:oracle:thin:@localhost:1521:xe
oracle.dbsource.username=talon
oracle.dbsource.password=talon
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.name=talon
spring.datasource.password=talon
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
When I run the spring project I have many java.sql.SQLException: ORA-01017: invalid username/password; logon denied errors. But the url, username and passwords are correct.
2018-01-12 13:05:06.521 ERROR 10220 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
...
2018-01-12 13:05:06.536 WARN 10220 --- [ main] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-01017: invalid username/password; logon denied
...
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-01017: invalid username/password; logon denied
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326) ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 61 common frames omitted
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied
...
2018-01-12 13:05:06.568 ERROR 10220 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: ORA-01017: invalid username/password; logon d
...
2018-01-12 13:05:07.169 ERROR 10220 --- [ main] org.hibernate.hql.spi.id.IdTableHelper : Unable obtain JDBC Connection
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
...
2018-01-12 13:05:07.191 INFO 10220 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-01-12 13:05:07.438 INFO 10220 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@75f9eccc: startup date [Fri Jan 12 13:05:04 CET 2018]; root of context hierarchy
2018-01-12 13:05:07.486 ERROR 10220 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
Before I've tried connecting to the same schema using DriverManager.getConnection
and I don't have any issue retrieving data that way.
我正在使用spring.datasource.name而不是spring.datasource.username
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.