Hi there, I was wondering if anyone might be able to shed some light on this issue I’m having. I’m trying to get reverse engineering working, so I can generate a Hibernate DAO layer from my Database schema, but I’m having some issues getting Hibernate to initial connect to my DB.
I’m using SQLServer 2000.
Here’s my script to create my DB:
Code:
IF OBJECT_ID ( 'sp_KillProcess', 'P' ) IS NOT NULL
DROP PROCEDURE sp_KillProcess;
GO
CREATE PROCEDURE sp_KillProcess
@databaseName varchar(30)
AS BEGIN
DECLARE @nFetchStatus int
DECLARE @nKillProcess int
DECLARE @sTemp nvarchar(10)
DECLARE curProcesses CURSOR LOCAL FAST_FORWARD READ_ONLY -- Get a cursor with the processes that have to die in order to be able to drop db
FOR
SELECT spid
FROM
Master..sysprocesses
LEFT JOIN Master..sysdatabases ON Master..sysprocesses.dbId = Master..sysdatabases.dbId
WHERE
[name] = @databaseName
and nt_userName <> 'AGibbons'
OPEN curProcesses
FETCH NEXT FROM curProcesses INTO --Gets the first process
@nKillProcess
SET @nFetchStatus = @@FETCH_STATUS
WHILE @nFetchStatus = 0 --Kill the processes
BEGIN
SET @sTemp = 'KILL ' + CAST(@nKillProcess as varchar(5))
EXEC(@sTemp)
FETCH NEXT FROM curProcesses INTO --Gets the next process
@nKillProcess
SET @nFetchStatus = @@FETCH_STATUS
END
CLOSE curProcesses
DEALLOCATE curProcesses
END
GO
EXEC sp_KillProcess 'goFurther'
go
use [goFurther]
go
declare @foreignKeys as nvarchar(1000)
declare @foreignKey as nvarchar(1000)
declare @nFetchStatus int
declare curProcesses cursor local fast_forward read_only
for
select
'if exists (select * from [sys].[foreign_keys] where [object_id] = object_id(N''[dbo].['
+ [constraint_name]
+ ']'') and [parent_object_id] = object_id(N''[dbo].['
+ [table_name]
+ ']'')) alter table '
+ [table_name]
+ ' drop constraint '
+ [constraint_name]
as foreignKeys
from [information_schema].[table_constraints]
where [constraint_type] = 'FOREIGN KEY'
open curProcesses
fetch next from curProcesses into @foreignKey
set @nFetchStatus = @@fetch_status
while @nFetchStatus = 0 --Kill the processes
begin
exec(@foreignKey)
fetch next from curProcesses into @foreignKey
set @nFetchStatus = @@fetch_status
end
close curProcesses
deallocate curProcesses
go
declare @tables nvarchar(1000)
declare @table nvarchar(1000)
declare @nFetchStatus int
declare curProcesses cursor local fast_forward read_only
for
select
'if exists (select * from [sys].[objects] where [object_id] = object_id(N''[dbo].['
+ [name]
+ ']'') and type in (N''U'')) drop table [dbo].['
+ [name]
+ ']'
as tables
from [sys].[objects]
where [type] = 'U'
open curProcesses
fetch next from curProcesses into @table
set @nFetchStatus = @@fetch_status
while @nFetchStatus = 0 --Kill the processes
begin
exec(@table)
fetch next from curProcesses into @table
set @nFetchStatus = @@fetch_status
end
close curProcesses
deallocate curProcesses
go
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'goFurther')
DROP DATABASE [goFurther]
USE [master]
GO
CREATE DATABASE [goFurther] ON PRIMARY(
NAME = N'goFurther_dat', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\goFurther.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 20%
)
LOG ON (
NAME = N'goFurther_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\goFurther_log.ldf' , SIZE = 1024KB , MAXSIZE = UNLIMITED, FILEGROWTH = 20%
)
COLLATE Latin1_General_CI_AS
USE [master]
GO
EXEC dbo.sp_dbcmptlevel @dbname=N'goFurther', @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [goFurther].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [goFurther] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [goFurther] SET ANSI_NULLS OFF
GO
ALTER DATABASE [goFurther] SET ANSI_PADDING OFF
GO
ALTER DATABASE [goFurther] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [goFurther] SET ARITHABORT OFF
GO
ALTER DATABASE [goFurther] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [goFurther] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [goFurther] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [goFurther] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [goFurther] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [goFurther] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [goFurther] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [goFurther] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [goFurther] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [goFurther] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [goFurther] SET DISABLE_BROKER
GO
ALTER DATABASE [goFurther] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [goFurther] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [goFurther] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [goFurther] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [goFurther] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [goFurther] SET READ_WRITE
GO
ALTER DATABASE [goFurther] SET RECOVERY FULL
GO
ALTER DATABASE [goFurther] SET MULTI_USER
GO
ALTER DATABASE [goFurther] SET PAGE_VERIFY TORN_PAGE_DETECTION
GO
ALTER DATABASE [goFurther] SET DB_CHAINING OFF
GO
use [goFurther]
go
create table [Location](
[id] int identity(1,1) not null,
[english] nvarchar(1000) null,
[japanese] nvarchar(1000) null,
[chinese] nvarchar(1000) null,
[korean] nvarchar(1000) null,
[perent] int null,
constraint [PK_Location] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [GamePlay](
[id] int identity(1,1) not null,
[game] int not null,
[play] int not null,
constraint [PK_GamePlay] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [PlayType](
[id] int identity(1,1) not null,
[desc] nvarchar(100) not null,
constraint [PK_PlayType] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [PlayColour](
[id] int identity(1,1) not null,
[desc] nvarchar(100) not null,
constraint [PK_PlayColour] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [PlaySymbol](
[id] int identity(1,1) not null,
[desc] nvarchar(100) not null,
constraint [PK_PlaySymbol] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [PlayComment](
[id] int identity(1,1) not null,
[english] nvarchar(1000) null,
[japanese] nvarchar(1000) null,
[chinese] nvarchar(1000) null,
[korean] nvarchar(1000) null,
[play] int not null,
constraint [PK_PlayComment] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [Play](
[id] int identity(1,1) not null,
[index] int not null,
[x] int not null,
[y] int not null,
[played] [datetime] null,
[playThread] int null,
[playType] int not null,
[playColour] int not null,
[playSymbol] int not null,
constraint [PK_Play] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [PlayThread](
[id] int identity(1,1) not null,
[perent] int null,
constraint [PK_PlayThread] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [User](
[id] int identity(1,1) not null,
[userName] nvarchar(100) unique not null,
[userPassword] nvarchar(100) not null,
[eMail] nvarchar(100) not null,
[player] int not null,
constraint [PK_User] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [Player](
[id] int identity(1,1) not null,
[creationDate] [datetime] not null,
[salutation] nvarchar(100) null,
[firstName] nvarchar(100) not null,
[middleNames] nvarchar(100) null,
[familyName] nvarchar(100) not null,
[eMail] nvarchar(100) null,
[location] int not null,
constraint [PK_Players] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [TeamPlayer](
[id] int identity(1,1) not null,
[team] int not null,
[player] int not null,
constraint [PK_TeamPlayer] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [Team](
[id] int identity(1,1) not null,
[name] nvarchar(100) unique not null,
[creationDate] [datetime] not null,
[location] int not null,
constraint [PK_Team] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [GameType](
[id] int identity(1,1) not null,
[desc] nvarchar(100) not null,
constraint [PK_GameType] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
create table [Game](
[id] int identity(1,1) not null,
[name] nvarchar(100) not null,
[creationDate] [datetime] not null,
[xSize] int not null,
[ySize] int not null,
[gameType] int not null,
[whiteTeam] int not null,
[blackTeam] int not null,
[location] int not null,
constraint [PK_Game] primary key clustered(
[id] asc
)
with (ignore_dup_key = off) on [primary]
)
on [primary]
alter table [Game] with check
add constraint [FK_BhiteTeam]
foreign key([whiteTeam])
references [Team] ([id])
alter table [Game] with check
add constraint [FK_BlackTeam]
foreign key([blackTeam])
references [Team] ([id])
alter table [Game] with check
add constraint [FK_GameLocation]
foreign key([location])
references [Location] ([id])
alter table [Play] with check
add constraint [FK_PlayType]
foreign key([playType])
references [PlayType] ([id])
alter table [Play] with check
add constraint [FK_PlayColour]
foreign key([playColour])
references [PlayColour] ([id])
alter table [Play] with check
add constraint [FK_PlaySymbol]
foreign key([playSymbol])
references [PlaySymbol] ([id])
alter table [Play] with check
add constraint [FK_PlayThread]
foreign key([playThread])
references [PlayThread] ([id])
alter table [PlayThread] with check
add constraint [FK_PlayThreadPerent]
foreign key([perent])
references [PlayThread] ([id])
alter table [Location] with check
add constraint [FK_LocationPerent]
foreign key([perent])
references [Location] ([id])
alter table [PlayComment] with check
add constraint [FK_PlayCommentPlay]
foreign key([play])
references [Play] ([id])
alter table [GamePlay] with check
add constraint [FK_Game]
foreign key([game])
references [Game] ([id])
alter table [GamePlay] with check
add constraint [FK_Play]
foreign key([play])
references [Play] ([id])
alter table [Player] with check
add constraint [FK_PlayerLocation]
foreign key([location])
references [Location] ([id])
alter table [Team] with check
add constraint [FK_TeamLocation]
foreign key([location])
references [Location] ([id])
alter table [TeamPlayer] with check
add constraint [FK_Team]
foreign key([team])
references [Team] ([id])
alter table [TeamPlayer] with check
add constraint [FK_Player]
foreign key([player])
references [Player] ([id])
alter table [Game] with check
add constraint [FK_GameType]
foreign key([gameType])
references [GameType] ([id])
if exists (select 1 from sys.sysusers where name = 'hibernate') drop user [hibernate]
create user [hibernate] FOR LOGIN [hibernate]
exec sp_addrolemember N'db_owner', N'hibernate'
insert into [Location]([english]) values('exeter')
insert into [Location]([english]) values('london')
insert into [User](
[userName],
[userPassword],
[eMail],
[player]
)
values(
'adamGibbons',
'password',
'adam.gibbons@connaught.plc.uk',
1
)
insert into [User](
[userName],
[userPassword],
[eMail],
[player]
)
values(
'bobSmith',
'password',
'bob.smith@connaught.plc.uk',
2
)
insert into [Player](
[creationDate],
[salutation],
[firstName],
[middleNames],
[familyName],
[eMail],
[location]
)
values(
current_timeStamp,
'Mr',
'Adam',
'S',
'Gibbons',
'adam.gibbons@connaught.plc.uk',
1
)
insert into [Player](
[creationDate],
[salutation],
[firstName],
[middleNames],
[familyName],
[eMail],
[location]
)
values(
current_timeStamp,
'Mr',
'Bob',
'X',
'Smith',
'bob.smith@connaught.plc.uk',
2
)
insert into [Team]([name], [Player].[creationDate], [location])
select [userName], [creationDate], 1
from [User]
inner join [Player] on [User].[player] = [Player].[id]
insert into [TeamPlayer]([team], [player])
select [Team].[id], [User].[id]
from [Team], [User]
where [Team].[name] = [User].[userName]
insert into [PlayType]([desc]) values('SETUP')
insert into [PlayType]([desc]) values('NORMAL')
insert into [PlayColour]([desc]) values('WHITE')
insert into [PlayColour]([desc]) values('BLACK')
insert into [PlaySymbol]([desc]) values('NONE')
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 1, 0, current_timeStamp, null, 1, 2, 1)
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 1, 1, current_timeStamp, null, 1, 2, 1)
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 1, 2, current_timeStamp, null, 1, 2, 1)
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 1, 3, current_timeStamp, null, 1, 2, 1)
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 0, 1, current_timeStamp, null, 1, 2, 1)
insert into [Play](
[index],
[x],
[y],
[played],
[playThread],
[playType],
[playColour],
[playSymbol]
)
values(0, 0, 3, current_timeStamp, null, 1, 2, 1)
declare @whiteTeamId as int
declare @blackTeamId as int
set @whiteTeamId = (
select [Team].[id] from Team
left join [TeamPlayer] on [TeamPlayer].[team] = [Team].[id]
left join [Player] on [TeamPlayer].[player] = [Player].[id]
left join [User] on [User].[player] = [Player].[id]
where [User].[userName] = 'adamGibbons'
)
set @blackTeamId = (
select [Team].[id] from [Team]
left join [TeamPlayer] on [TeamPlayer].[team] = [Team].[id]
left join [Player] on [TeamPlayer].[player] = [Player].[id]
left join [User] on [User].[player] = [Player].[id]
where [User].[userName] = 'bobSmith'
)
insert into [GameType]([desc]) values('NORMAL')
insert into [Game](
[name],
[creationDate],
[xSize],
[ySize],
[gameType],
[whiteTeam],
[blackTeam],
[location]
)
values(
'Test Game 001',
current_timeStamp,
'19',
'19',
1,
@whiteTeamId,
@blackTeamId,
1
)
insert into [GamePlay](
[game],
[play]
)
select 1, [Play].[id] from [Play]
declare @dispTables nvarchar(1000)
declare @dispTable nvarchar(1000)
declare @nFetchStatus int
declare curProcesses cursor local fast_forward read_only
for
select
'select * from ['
+ [name]
+ ']'
as dispTables
from [sys].[objects]
where [type] = 'U'
open curProcesses
fetch next from curProcesses into @dispTable
set @nFetchStatus = @@fetch_status
while @nFetchStatus = 0 --Kill the processes
begin
exec(@dispTable)
fetch next from curProcesses into @dispTable
set @nFetchStatus = @@fetch_status
end
close curProcesses
deallocate curProcesses
go
I’ve read the How To Ask For Help section, the road map, sample chapter 2, reference docs, search the forums and in the end caved in and tried to just get the helloworld-native example to run. But I always seem to run into the same problem:
Code:
Buildfile: C:\helloworld-native\build.xml
compile:
[mkdir] Created dir: C:\helloworld-native\build
[javac] Compiling 3 source files to C:\helloworld-native\build
copymetafiles:
[copy] Copying 3 files to C:\helloworld-native\build
run:
[java] 05:05:59,895 WARN BasicResourcePool:1222 - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e0b6f5 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
[java] 05:06:00,255 WARN SettingsFactory:109 - Could not obtain connection metadata
[java] java.sql.SQLException: Connections could not be acquired from the underlying database!
[java] at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
[java] at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
[java] at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
[java] at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
[java] at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
[java] at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
[java] at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
[java] ... 7 more
[java] 05:06:00,895 WARN BasicResourcePool:1222 - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3bc257 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
[java] 05:06:00,895 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: null
[java] 05:06:00,895 ERROR JDBCExceptionReporter:72 - Connections could not be acquired from the underlying database!
[java] Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
[java] at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
[java] at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
[java] at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
[java] at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
[java] at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
[java] at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
[java] at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
[java] at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
[java] at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
[java] at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
[java] ... 5 more
[java] Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
[java] at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
[java] at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
[java] at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
[java] ... 8 more
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 minute 5 seconds
I would spend more time look at this myself, but it’s 5am here now, and I was hoping someone might be able to provide me with some clues that I can use to try and resolve the problem in the morning.
I’m sure I’m missing something trivial but I’ve been tearing my hair out for hours now and not really got anywhere. :(
Any help would be much appreciated!
Thanks in advance, and sorry for the long post. >.>
Cheers
Adam