orcal is a Object-Relation DBMS, so it can create the object type like Object-Oriented object.
for example:
CREATE TYPE product_typ AS OBJECT (
id NUMBER,
name VARCHAR2(10),
description VARCHAR2(22),
price NUMBER(5, 2),
days_valid NUMBER,
-- declare the get_sell_by_date() member function([i]method),
-- get_sell_by_date() returns the date by which the
-- product must be sold[/i]
MEMBER FUNCTION get_sell_by_date RETURN DATE
);
CREATE TYPE BODY product_typ AS MEMBER FUNCTION get_sell_by_date RETURN DATE IS
sell_by_date DATE;
BEGIN
SELECT
days_valid + sysdate
INTO
sell_by_date
FROM
dual;
-- return the sell by date
RETURN sell_by_date;
END; END;
-- create the tables with oracle object type like this
CREATE TABLE products (
product product_typ,
quantity_in_stock NUMBER
);
When insert row to table products, I should do like this:
INSERT INTO products (
product,
quantity_in_stock
) VALUES (
product_typ(2, 'Sardines', '12 oz box of sardines', 2.99, 5),
25
);
When I select rows from table products ,the statement like this:
SELECT p.product FROM products p WHERE p.product.id = 1;
the result like this:
PRODUCT(ID, NAME, DESCRIPTION, PRICE, DAYS_VALID) ---------------------------------------------------------------------- PRODUCT_TYPE(1, 'Pasta', '20 oz bag of pasta', 3.95, 10)
SELECT * FROM products;
PRODUCT(ID, NAME, DESCRIPTION, PRICE, DAYS_VALID) QUANTITY_IN_STOCK --------------------------------------------------------------------------------------------- PRODUCT_TYP(1, 'Pasta', '20 oz bag of pasta', 3.95, 10) 50
update row in table products like this:
UPDATE products p
SET p.product.description='30 oz bag of pasta'
WHERE p.product.id=1
can i map the table products to Java class with Hibernate? if yes, then how can i do for this?
|